Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(research): close the checklist when a run ends; one progress display while it runs

Salman Qureshi155e4866ba18
diff --git a/apps/desktop/src/views/chat/Conversation.tsx b/apps/desktop/src/views/chat/Conversation.tsx
index 00c8194f..ab703491 100644
--- a/apps/desktop/src/views/chat/Conversation.tsx
+++ b/apps/desktop/src/views/chat/Conversation.tsx
@@ -35,6 +35,7 @@ export function Conversation({ header, empty, composer }: { header: ReactNode; e
const waiting = useConversation((s) => s.waiting);
const stopping = useConversation((s) => s.stopping);
const notice = useConversation((s) => s.notice);
+ const researching = useConversation((s) => s.research?.run?.state === "running");
const scroller = useRef<HTMLDivElement>(null);
const content = useRef<HTMLDivElement>(null);
const [visible, setVisible] = useState(PAGE);
@@ -143,7 +144,8 @@ export function Conversation({ header, empty, composer }: { header: ReactNode; e
</div>
<ResearchBar />
- <PlanCard surface={composer.surface} />
+ {/* While research runs, its bar shows the questions (and Details the checklist): one progress display, not two. */}
+ {!researching && <PlanCard surface={composer.surface} />}
<Composer {...composer} />
</section>
);
diff --git a/src/core/agent.ts b/src/core/agent.ts
index 0cd4561f..e43c8551 100644
--- a/src/core/agent.ts
+++ b/src/core/agent.ts
@@ -46,7 +46,7 @@ import { WebChannel } from '../channels/web.js';
import type { ArrowSelectOption } from '../utils/arrow-select.js';
import { setAskUserHandler } from '../capabilities/interaction/ask-user.js';
import { classifyResearchIntent } from './research-intent.js';
-import { coverageSection, parsePlanLines, reportBody, reportFileName, RESEARCH_PLAN_SYSTEM, RESEARCH_WRITE_SYSTEM, sourcesAppendix, unansweredFrom, type ResearchRun } from './research-run.js';
+import { closePlan, coverageSection, parsePlanLines, reportBody, reportFileName, RESEARCH_PLAN_SYSTEM, RESEARCH_WRITE_SYSTEM, sourcesAppendix, unansweredFrom, type ResearchRun } from './research-run.js';
import type { SpotifyClient } from '../spotify/client.js';
import { fallbackSessionTitle, isThinOpening, normalizeGeneratedSessionTitle, SessionResolutionError, type SessionRepository } from '../sessions/index.js';
import { PLAYER_CONTROLS, handlePlayerAction, formatNowPlaying } from '../spotify/ui.js';
@@ -1231,6 +1231,7 @@ export class Agent {
run.setQuestions(answer.questions);
if (answer.timedOut) channel.sendNotice('No answer on the plan, so the research started with it as proposed.', msg.channelId);
channel.sendPlan(run.questions.map((label) => ({ label, status: 'pending' })), msg.channelId);
+ run.planned = true;
return true;
} finally {
clearInterval(keepAlive);
@@ -4823,6 +4824,12 @@ export class Agent {
}
if (researchRun) {
researchRun.end('failed', 'it ended before writing a report');
+ // Close the checklist the run worked through (models rarely tick the last step).
+ const planChannel = this.channels.getChannelForMessage(msg);
+ if (researchRun.planned && planChannel instanceof WebChannel) {
+ const closed = closePlan(planChannel.plans.get(msg.channelId)?.steps ?? [], researchRun.outcome);
+ if (closed) planChannel.sendPlan(closed, msg.channelId);
+ }
this.emitResearch(msg, researchRun);
this.researchMode.endRun();
}
diff --git a/src/core/research-run.test.ts b/src/core/research-run.test.ts
index aa6b09ee..9f4bb0fa 100644
--- a/src/core/research-run.test.ts
+++ b/src/core/research-run.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { coverageSection, fetchFailure, parsePlanLines, reportBody, reportFileName, ResearchRun, sourcesAppendix, stepFailure, unansweredFrom } from './research-run.js';
+import { closePlan, coverageSection, fetchFailure, parsePlanLines, reportBody, reportFileName, ResearchRun, sourcesAppendix, stepFailure, unansweredFrom } from './research-run.js';
import { ResearchMode } from './research-mode.js';
const page = (title: string) => `# ${title}\n\n${'Real page text about the topic. '.repeat(20)}`;
@@ -148,3 +148,34 @@ describe('the report kept', () => {
expect(reportBody(article, { content: '# Short\n\nnotes' })).toBe(article.trim());
});
});
+
+describe('the checklist when a run ends', () => {
+ const plan = [
+ { label: 'Who builds them', status: 'done' as const },
+ { label: 'What they cost', status: 'active' as const },
+ { label: 'Synthesize findings into a report', status: 'pending' as const },
+ ];
+
+ it('a finished run ticks every step (models skip the last one)', () => {
+ expect(closePlan(plan, 'done')?.map((s) => s.status)).toEqual(['done', 'done', 'done']);
+ });
+
+ it('a report written after a cut ticks the writing, keeps the unreached questions open', () => {
+ expect(closePlan(plan, 'partial')?.map((s) => s.status)).toEqual(['done', 'pending', 'done']);
+ });
+
+ it('a stopped or failed run leaves it, and an already-closed plan is no change', () => {
+ expect(closePlan(plan, 'stopped')).toBeNull();
+ expect(closePlan(plan, 'failed')).toBeNull();
+ expect(closePlan(plan.map((s) => ({ ...s, status: 'done' as const })), 'done')).toBeNull();
+ expect(closePlan([], 'done')).toBeNull();
+ });
+
+ it('only a run that made the plan closes it', () => {
+ const run = new ResearchRun('t', 's1', 10);
+ expect(run.planned).toBe(false);
+ run.observe('update_plan', { steps: [] }, 'Plan updated');
+ expect(run.planned).toBe(true);
+ expect(run.snapshot().steps).toBe(1);
+ });
+});
diff --git a/src/core/research-run.ts b/src/core/research-run.ts
index 980fbdfc..7867931f 100644
--- a/src/core/research-run.ts
+++ b/src/core/research-run.ts
@@ -113,6 +113,8 @@ export class ResearchRun {
steps = 0;
/** The owner asked to stop searching and write the report now. */
finishRequested = false;
+ /** This run made (or was given) the plan checklist, so its end may close it. */
+ planned = false;
outcome: 'running' | ResearchOutcome = 'running';
endedAt?: number;
cut?: string;
@@ -138,6 +140,10 @@ export class ResearchRun {
this.steps++;
const args = (input ?? {}) as Record<string, unknown>;
const text = typeof result === 'string' ? result : JSON.stringify(result ?? '');
+ if (tool === 'update_plan') {
+ this.planned = true;
+ return;
+ }
if (tool === 'web_search') {
this.phase = 'searching';
const query = typeof args.query === 'string' ? args.query : '';
@@ -288,11 +294,28 @@ export function sourcesAppendix(run: ResearchRun): string {
return lines.join('\n');
}
+const WRITING_STEP = /^(synthesi[sz]e|write|compile|draft|summari[sz]e|produce|create|assemble|finali[sz]e)\b/i;
+
+/**
+ * The checklist when a run ends. Models tick the research steps as they go
+ * but rarely the last one ("Write the report"), so a finished run left the
+ * checklist stuck on it. Finished: every step is done. A report written after
+ * a cut: the writing step is done, the questions it didn't reach stay open.
+ * Stopped or failed: left as it was. Null = nothing to change.
+ */
+export function closePlan<T extends { label: string; status: 'pending' | 'active' | 'done' }>(steps: T[], outcome: ResearchOutcome | 'running'): T[] | null {
+ if (!steps.length) return null;
+ let next: T[];
+ if (outcome === 'done') next = steps.map((s) => ({ ...s, status: 'done' as const }));
+ else if (outcome === 'partial') next = steps.map((s) => (WRITING_STEP.test(s.label.trim()) ? { ...s, status: 'done' as const } : s.status === 'active' ? { ...s, status: 'pending' as const } : s));
+ else return null;
+ return next.some((s, i) => s.status !== steps[i].status) ? next : null;
+}
+
/** Plan steps the model hasn't marked done: what the report doesn't cover yet. */
export function unansweredFrom(plan: Array<{ label: string; status: string }> | undefined): string[] {
// "Write the report" steps are the writing, not a question the report misses.
- const writing = /^(synthesi[sz]e|write|compile|draft|summari[sz]e|produce|create|assemble|finali[sz]e)\b/i;
- return (plan ?? []).filter((s) => s.status !== 'done' && !writing.test(s.label.trim())).map((s) => s.label);
+ return (plan ?? []).filter((s) => s.status !== 'done' && !WRITING_STEP.test(s.label.trim())).map((s) => s.label);
}
/**