fix: show empty work preview without invoking the Agent

This commit is contained in:
鲨鱼辣椒
2026-09-29 16:31:19 +08:00
parent 077184aaba
commit 0167d361ed
11 changed files with 391 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import type { CodingConversationRuntime } from './contracts';
import { OPEN_WORK_PROMPT, type WorkPreviewResult } from '../../shared/coding-work-preview';
import { codingRecovery } from '../../shared/coding-recovery';
import type { AgentBrowserSnapshot } from '../../shared/agent-browser';
import { inspectWorkPresence, type WorkPresence } from './work-presence';
type Project = { id: string; path: string };
type Attempt = {
@@ -43,6 +44,7 @@ export class CodingWorkPreviewService {
runtime: Pick<CodingConversationRuntime, 'getDiagnostics'>;
ensureActive(project: Project): Promise<void>;
responds?(url: string): Promise<boolean>;
inspectWork?(projectPath: string): Promise<WorkPresence>;
}) {}
remember(project: Project, snapshot: AgentBrowserSnapshot): void {
@@ -112,10 +114,19 @@ export class CodingWorkPreviewService {
const list = await conversations.listConversations(project.id);
const projectIds = new Set(list.map(({ id }) => id));
const busy = this.deps.runtime.getDiagnostics().workers.some((worker) => (
const busy = () => this.deps.runtime.getDiagnostics().workers.some((worker) => (
projectIds.has(worker.conversationId) && ['starting', 'queued', 'running'].includes(worker.stage)
));
if (busy) return { status: 'waiting' };
if (busy()) return { status: 'waiting' };
const presence = await (this.deps.inspectWork ?? inspectWorkPresence)(project.path);
await this.deps.ensureActive(project);
if (this.pages.has(project.id)) return this.check(project, requestId, conversationId);
if (busy()) return { status: 'waiting' };
if (presence === 'empty') {
// No cached terminal attempt: the same tab/request can discover newly made work.
this.attempts.delete(project.id);
return { status: 'empty' };
}
let conversation = attempt.conversationId
? await conversations.getConversation(attempt.conversationId)
: list.find((item) => !item.archivedAt);