Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): 归档的后台任务仍标伙伴归属;实时结果卡按子任务目录解析相对链接

Chrisb83ff9803d7f
diff --git a/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx b/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx
index 513f2dfe2f..7c4b528249 100644
--- a/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx
@@ -292,7 +292,10 @@ export function BotTaskCard({
: (row?.artifacts ?? []).flatMap((file) => (file.absolutePath ? [file.absolutePath] : []));
// Older remote hosts may omit the list; never let a missing field break the card.
const fileCount = frozen ? frozen.artifacts.length : (row?.artifacts?.length ?? 0);
- const workingDir = frozen?.workingDir ?? fileContext.workingDir;
+ // Relative links in the result belong to the background task's own directory, which may
+ // differ from the Bot's main task: the frozen receipt records it, the live card reads the
+ // child session's. The surrounding chat's directory is only the last resort.
+ const workingDir = frozen?.workingDir ?? session?.workingDir ?? fileContext.workingDir;
const canOpen = Boolean(childSessionId) && !ref.originConflict;
const canAddNote = state === 'running' && Boolean(childSessionId) && !ref.sourceDeviceId && !frozen;
const resultLabel =
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx
index 5f8db32bc8..34625e45d9 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx
@@ -48,7 +48,7 @@ vi.mock('@/contexts/PrRefsContext', () => ({
usePrStatuses: () => ({ statuses: new Map(), successfulStatuses: new Map(), refreshError: false }),
}));
vi.mock('@/components/chat/MarkdownRenderer', () => ({
- MarkdownRenderer: ({ content }: any) => <div data-testid="markdown">{content}</div>,
+ MarkdownRenderer: ({ content, workingDir }: any) => <div data-testid="markdown" data-working-dir={workingDir}>{content}</div>,
}));
vi.mock('@/components/chat/ChatSessionFileContext', () => ({
useChatSessionFile: () => ({ origin: { kind: 'local' }, sessionId: 'parent', workingDir: '/parent' }),
@@ -257,6 +257,8 @@ it('shows the result summary when completed and expands the result in place', as
artifacts: [{ path: 'a.ts', absolutePath: '/child/a.ts', status: 'modified' }] });
render(<BotSessionTaskCard data={data()} sessionId="parent" />);
expect(cardState()).toBe('completed');
+ // The child session (title, working directory) has loaded.
+ await screen.findByRole('button', { name: 'Current title' });
expect(screen.getByText('Retry capped at 3.')).toBeTruthy();
expect(screen.getByText(/bots\.collab\.tookTime/)).toBeTruthy();
expect(screen.queryByRole('button', { name: /bots\.collab\.stop/ })).toBeNull();
@@ -265,6 +267,8 @@ it('shows the result summary when completed and expands the result in place', as
fireEvent.click(toggle);
expect(screen.getAllByTestId('markdown').map((node) => node.textContent))
.toEqual(['Retry capped at 3.', '[a.ts](</child/a.ts>)']);
+ // Relative links in a live result resolve against the background task's own directory, not the chat's.
+ expect(screen.getAllByTestId('markdown').map((node) => node.getAttribute('data-working-dir'))).toEqual(['/child', '/child']);
expect(screen.getByRole('button', { name: /bots\.collab\.collapseResult/ }).getAttribute('aria-expanded')).toBe('true');
expect(screen.getByRole('button', { name: /bots\.collab\.artifactCount/ })).toBeTruthy();
});
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botFollowMark.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botFollowMark.test.tsx
index 9bd7d2cd2b..baec60a289 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botFollowMark.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botFollowMark.test.tsx
@@ -134,6 +134,14 @@ describe('useSessionDelegatingBot', () => {
expect(followScopes).toHaveBeenCalledTimes(1);
});
+ it('keeps naming the Bot for its archived background task, while the follow mark stays active-only', async () => {
+ followScopes.mockResolvedValueOnce([{ botId: 'bot-1', sessionIds: ['s2'], delegatedSessionIds: ['s2'] }]);
+ const archived = session({ id: 's2', status: 'archived' });
+ await act(async () => render(<><Owner session={archived} /><Row session={archived} /></>));
+ expect(screen.getByTestId('owner').textContent).toBe('Dash');
+ expect(screen.queryByTestId('bot-follow-mark')).toBeNull();
+ });
+
it('does not guess from an older host that only lists responsibilities', async () => {
await act(async () => render(<Owner session={session()} />));
expect(screen.getByTestId('owner').textContent).toBe('none');
diff --git a/apps/desktop/src/renderer/features/bots/botFollowScopes.ts b/apps/desktop/src/renderer/features/bots/botFollowScopes.ts
index 9389b3851e..9fa5139e16 100644
--- a/apps/desktop/src/renderer/features/bots/botFollowScopes.ts
+++ b/apps/desktop/src/renderer/features/bots/botFollowScopes.ts
@@ -108,18 +108,31 @@ function getSnapshot(): readonly BotFollowScope[] {
return scopes;
}
-/** 能被伙伴跟进的任务:本机、未归档、普通来源、不是伙伴自己的任务或 Orca worker。 */
-function isFollowableSession(session: Session): boolean {
- if (session.status !== 'active') return false;
+/** 本机普通任务:不是远程任务、伙伴自己的主任务或 Orca worker。 */
+function isLocalPlainSession(session: Session): boolean {
if (session.remoteHostId || session.deviceLinkDeviceId) return false;
if (session.source === 'bot' || session.orcaRole === 'worker') return false;
return isWorkbenchTaskSource(session.source);
}
-function useScopedBots(session: Session, ids: (scope: BotFollowScope) => readonly string[] | undefined): BotProfile[] {
+/** 能被伙伴跟进的任务:本机、未归档的普通任务。 */
+function isFollowableSession(session: Session): boolean {
+ return session.status === 'active' && isLocalPlainSession(session);
+}
+
+/** 伙伴自己开的后台任务:归档后从工作台打开仍要标明归属并能回到该伙伴(cindy-bots-runtime.md 任务入口)。 */
+function isDelegatableSession(session: Session): boolean {
+ return (session.status === 'active' || session.status === 'archived') && isLocalPlainSession(session);
+}
+
+function useScopedBots(
+ session: Session,
+ eligible: (session: Session) => boolean,
+ ids: (scope: BotFollowScope) => readonly string[] | undefined,
+): BotProfile[] {
const followScopes = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
const profiles = useBotProfiles();
- const followable = isFollowableSession(session);
+ const followable = eligible(session);
const sessionId = session.id;
return useMemo(() => {
if (!followable || followScopes.length === 0) return [];
@@ -141,15 +154,15 @@ const delegatedIds = (scope: BotFollowScope) => scope.delegatedSessionIds;
/** 正在负责这件任务的伙伴(按名字排序;隐藏、停用的伙伴不显示)。 */
export function useSessionFollowers(session: Session): BotProfile[] {
- return useScopedBots(session, responsibleIds);
+ return useScopedBots(session, isFollowableSession, responsibleIds);
}
/**
* 这件任务是哪位伙伴自己开的后台任务(委派子任务);主人的任务被伙伴接手只算「在跟进」,
- * 不算伙伴的后台任务。旧宿主没有这份投影时不猜。
+ * 不算伙伴的后台任务。已归档的后台任务仍标归属。旧宿主没有这份投影时不猜。
*/
export function useSessionDelegatingBot(session: Session): BotProfile | null {
- return useScopedBots(session, delegatedIds)[0] ?? null;
+ return useScopedBots(session, isDelegatableSession, delegatedIds)[0] ?? null;
}
export const __testing = {
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index f96b21a4a8..643c039dcb 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -338,7 +338,7 @@ Session 任务遵守同一套机制与呈现契约:
只在本轮执行结束后由伙伴明确选择切换。切换不自动重放工作;伙伴结合原目标和已完成动作,
再决定是否向同一任务发补充消息。未配置的供应商或型号不可擅自加入候选。
- **任务入口(2026-10-15 改为一张卡)**:Desktop 发起方消息流里,一条后台任务从开始到结束只有一张状态卡(`BotTaskCard`),状态原地变化,不再是下划线文本链接加独立结果卡。卡的第一行是状态字形(排队/运行转圈、等确认蓝点、完成绿点、失败红点)、任务标题(点击进入原任务)与「后台任务 · 引擎 · 用时」;第二行按状态写当前动作与已做时长、等你确认什么、结果摘要或错误;操作收成小胶囊:看看/看过程、补一句(运行中、本机任务才有;回车发送,等同 `message_session_task`)、文件数、PR 状态标、展开/收起结果、停止。标题与 harness 读取同一个 Session;运行状态来自原任务的真实运行信号,不从委派终态推断事项完成。远端伙伴的卡只读。Mobile 继续使用既有任务卡入口,存储与绑定合同不变。
- **同一个后台任务只有一张脸**:通知、聊天里的卡片与主侧栏进入伙伴开的后台任务都走工程视图 `/cc-agent/:id`(diff、模型选择照常),顶部多一枚「<伙伴> 的后台任务」小标回到该伙伴;伙伴主任务始终 `/bots/:id`,归档历史 `/bots/:id/history/:sid`,群专线不可单独导航。路由由 `botRouteForOwnedSession` 统一给出,`resolveSessionRoute` 只读已加载的伙伴投影、不等 IPC。
+ **同一个后台任务只有一张脸**:通知、聊天里的卡片与主侧栏进入伙伴开的后台任务都走工程视图 `/cc-agent/:id`(diff、模型选择照常),顶部多一枚「<伙伴> 的后台任务」小标回到该伙伴(只认伙伴自己发起的委派子任务,主人的任务被伙伴接手只有侧栏「在跟进」标记;后台任务归档后从工作台打开仍带这枚小标;结果里的相对链接按该后台任务自己的工作目录解析,不按伙伴主任务目录);伙伴主任务始终 `/bots/:id`,归档历史 `/bots/:id/history/:sid`,群专线不可单独导航。路由由 `botRouteForOwnedSession` 统一给出,`resolveSessionRoute` 只读已加载的伙伴投影、不等 IPC。
工作台的 Cindy 任务进入与其它条目同一份四组列表(见 6.3),不再另有 `SessionCard` 列表与独立的「已归档」折叠;已归档的负责任务按页接在「做完」最底部,只依据原 `status=archived` 字段,打开只看不取消归档,恢复走条目菜单的显式操作。分页仅为本机可信 renderer 扩展,不向旧远端假报支持。
- **执行结果入口**:Desktop 的冻结结果用同一张后台任务卡呈现(附在收尾回复下时结果默认展开,独立回执默认收起);完成结果属于伙伴收尾回复末尾的紧凑附件,正文先读,卡片与该条回复同列、同一容器归属。宿主以本轮实际消费的完成信号绑定冻结结果,成功收尾后随回复持久保存;同轮多结果分别附上,不按相邻消息、时间或正文猜配,不把所有卡移到时间线末尾。忙时尚未消费的队列不参与当前回复;每个结果还必须有该完成输入持久化之后生成的新正文,旧正文延迟落库、同毫秒无法确认顺序或输入记录缺失时保留独立入口。重复信号不重复绑定,续跑按执行代次保留独立结果。
原任务卡和消息顺序不变。结果先按既有机制独立持久化;没有最终正文、失败或中断、关联读取失败、旧记录没有关联、或仅加载到原回执时,保留独立结果入口,不伪造总结、不改用户历史库。关联回复加载后,其对应独立回执只在伙伴展示投影中收起。旧客户端忽略新增的可选 `botTaskResults`,继续显示独立回执。新回执保存当次子任务标题;旧回执只读回退到已有任务标题,再回退到目标首行。附件冻结的状态、正文、文件与错误不从当前任务覆盖。普通任务、执行调度与自动化静默不改变。