Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

fix(groups): handoff paths, repair outputs, pause and stop states read correctly

leen.zhou82622c6ecc61
diff --git a/apps/desktop/src/renderer/features/group/tasks/GroupPlanProgress.tsx b/apps/desktop/src/renderer/features/group/tasks/GroupPlanProgress.tsx
index 8c88e22..6455040 100644
--- a/apps/desktop/src/renderer/features/group/tasks/GroupPlanProgress.tsx
+++ b/apps/desktop/src/renderer/features/group/tasks/GroupPlanProgress.tsx
@@ -143,6 +143,9 @@ export function GroupPlanProgressView({
const ownerIds = new Map(card.owners.map((entry) => [entry.stepId, entry.botId]));
const owner = (stepId: string) => bots?.get(ownerIds.get(stepId) ?? "");
const share = progress.total ? Math.round((progress.passed / progress.total) * 100) : 0;
+ const terminalStopped =
+ progress.status === "cancelled" ||
+ (progress.status === "failed" && progress.stoppedReason === "user_stopped");
return (
<div className={styles.modify} aria-live="polite">
<div className={styles.head}>
@@ -168,7 +171,9 @@ export function GroupPlanProgressView({
: step.verdict?.verdict === "fail"
? "failed"
: step.paused
- ? "stopped"
+ ? terminalStopped
+ ? "stopped"
+ : "waiting"
: dots[step.status]
}
className={styles.dot}
@@ -193,7 +198,7 @@ export function GroupPlanProgressView({
count: step.verdict.failures.length,
})
: step.paused
- ? t("group.plan.step.paused")
+ ? t(terminalStopped ? "group.plan.step.stopped" : "group.plan.step.paused")
: t(`group.plan.step.${step.status}`)}
{step.status === "running" && step.attempt > 0
? ` · ${t("group.plan.attempt", { n: step.attempt + 1 })}`
diff --git a/apps/mobile/src/features/chat/controls/group-plan.ts b/apps/mobile/src/features/chat/controls/group-plan.ts
index 1b6c927..9472974 100644
--- a/apps/mobile/src/features/chat/controls/group-plan.ts
+++ b/apps/mobile/src/features/chat/controls/group-plan.ts
@@ -100,7 +100,10 @@ export interface PlanStepView {
attempt: number;
}
type StepState = GroupPlanProgress["steps"][number];
-function stepLook(state: StepState | undefined): { mark: StepMark; label: MobileKey } {
+function stepLook(
+ state: StepState | undefined,
+ terminalStopped: boolean,
+): { mark: StepMark; label: MobileKey } {
if (!state) return { mark: "waiting", label: "gpStepWaiting" };
// Same order as the desktop progress dots: a resolved verdict wins over the raw state.
if (state.verdictResolution?.kind === "repaired") return { mark: "done", label: "gpStepDone" };
@@ -108,7 +111,11 @@ function stepLook(state: StepState | undefined): { mark: StepMark; label: Mobile
return { mark: "skipped", label: "gpStepSkipped" };
if (state.status === "passed") return { mark: "done", label: "gpStepDone" };
// Stopped by the group's pause: not a failure, and it runs again when the group continues.
- if (state.paused) return { mark: "waiting", label: "gpStepPaused" };
+ if (state.paused)
+ return {
+ mark: "waiting",
+ label: terminalStopped ? "gpStepStopped" : "gpStepPaused",
+ };
if (state.status === "blocked") return { mark: "attention", label: "gpStepNeedsYou" };
if (state.status === "failed") return { mark: "failed", label: "gpStepFailed" };
if (state.status === "running")
@@ -130,6 +137,9 @@ export function planView(state: GroupPlanState) {
const ids = progress?.steps.length
? progress.steps.map((step) => step.stepId)
: card.plan.steps.map((step) => step.id);
+ const terminalStopped =
+ progress?.status === "cancelled" ||
+ (progress?.status === "failed" && progress.stoppedReason === "user_stopped");
const steps = ids.map((id): PlanStepView => {
const step = defined.get(id);
const fact = facts.get(id);
@@ -138,7 +148,7 @@ export function planView(state: GroupPlanState) {
title: step?.title ?? id,
task: step?.task === undefined ? undefined : visibleTaskText(step.task),
botId: owners.get(id),
- ...stepLook(fact),
+ ...stepLook(fact, terminalStopped),
attempt: fact?.attempt ?? 0,
};
});
diff --git a/apps/mobile/src/i18n/sections/group-plan.ts b/apps/mobile/src/i18n/sections/group-plan.ts
index 1ca70df..2f6f761 100644
--- a/apps/mobile/src/i18n/sections/group-plan.ts
+++ b/apps/mobile/src/i18n/sections/group-plan.ts
@@ -13,6 +13,7 @@ export const groupPlanZh = {
gpStepFailed: "未通过",
gpStepSkipped: "已跳过",
gpStepPaused: "已暂停",
+ gpStepStopped: "已停止",
gpAttempt: "第 {n} 次",
gpPlanPending: "等你确认 · 在电脑上查看并开始",
gpPlanReady: "已校验,尚未开始",
@@ -57,6 +58,7 @@ export const groupPlanEn: Record<keyof typeof groupPlanZh, string> = {
gpStepFailed: "Failed",
gpStepSkipped: "Skipped",
gpStepPaused: "Paused",
+ gpStepStopped: "Stopped",
gpAttempt: "attempt {n}",
gpPlanPending: "Waiting for you · review and start it on the computer",
gpPlanReady: "Validated, not started yet",
diff --git a/packages/i18n/src/sections/group.ts b/packages/i18n/src/sections/group.ts
index 4c048ad..f91bd1b 100644
--- a/packages/i18n/src/sections/group.ts
+++ b/packages/i18n/src/sections/group.ts
@@ -99,6 +99,7 @@ export const groupZh = {
"group.plan.step.failed": "未通过",
"group.plan.step.skipped": "已跳过",
"group.plan.step.paused": "已暂停",
+ "group.plan.step.stopped": "已停止",
"group.plan.attempt": "第 {n} 次尝试",
"group.plan.workspace.own": "在自己的独立工作区里写",
"group.plan.workspace.merging": "已通过,等待合并",
@@ -560,6 +561,7 @@ export const groupEn: Record<keyof typeof groupZh, string> = {
"group.plan.step.failed": "Failed",
"group.plan.step.skipped": "Skipped",
"group.plan.step.paused": "Paused",
+ "group.plan.step.stopped": "Stopped",
"group.plan.attempt": "attempt {n}",
"group.plan.workspace.own": "Writing in its own workspace",
"group.plan.workspace.merging": "Passed, waiting to merge",
diff --git a/packages/orchestration/src/conversations/groups/group-chat-control.ts b/packages/orchestration/src/conversations/groups/group-chat-control.ts
index 837c17e..6170bb5 100644
--- a/packages/orchestration/src/conversations/groups/group-chat-control.ts
+++ b/packages/orchestration/src/conversations/groups/group-chat-control.ts
@@ -53,7 +53,7 @@ export function postProgramNotice(
service: GroupService,
group: Pick<Group, "id" | "conversationId" | "coordinatorBotId">,
kind: ChatControl,
- stepTitle?: string,
+ stepTitles?: readonly string[],
) {
const zh = service.deps.chat.currentLanguage() === "zh";
const text =
@@ -61,10 +61,10 @@ export function postProgramNotice(
? zh
? "已暂停:正在做的步骤已停下,进度保留。说「继续」或点「继续」恢复。"
: 'Paused: the running step stopped and progress is kept. Say "continue" or tap Continue to resume.'
- : stepTitle
+ : stepTitles?.length
? zh
- ? `已继续,从「${stepTitle}」接着做。`
- : `Resumed from "${stepTitle}".`
+ ? `已继续,从「${stepTitles.join("」「")}」接着做。`
+ : `Resumed from "${stepTitles.join('", "')}".`
: zh
? "已继续。"
: "Resumed.";
@@ -163,7 +163,12 @@ export async function resumeGroupNow(
}
between?.();
const resumed = service.resumeAfterPause(updated, false);
- const notice = postProgramNotice(service, group, "resume", resumed[0]?.title);
+ const notice = postProgramNotice(
+ service,
+ group,
+ "resume",
+ resumed.map((step) => step.title),
+ );
log(service, event, group.id, 0, resumed.length);
return { notice, resumed };
}
diff --git a/packages/orchestration/src/conversations/groups/group-handoff-text.ts b/packages/orchestration/src/conversations/groups/group-handoff-text.ts
index c71e1ba..a70e455 100644
--- a/packages/orchestration/src/conversations/groups/group-handoff-text.ts
+++ b/packages/orchestration/src/conversations/groups/group-handoff-text.ts
@@ -1,4 +1,4 @@
-import { resolve } from "node:path";
+import { join } from "node:path";
import { citationFailureHint, deliveryCorrectionText } from "@pibot/brain/orchestration-kit";
import type { DeliveryItem, HandoffSpec } from "@pibot/protocol-base";
import type { HandoffRecord } from "@pibot/storage";
@@ -50,7 +50,7 @@ function acceptanceLine(item: HandoffSpec["acceptance"][number], spec: HandoffSp
export function handoffBrief(spec: HandoffSpec, base: string | null, language: Language) {
const zh = language === "zh";
const lines = [zh ? "【交接要求】" : "[Hand-off]"];
- const files = spec.files.map((path) => (base ? resolve(base, path) : path));
+ const files = spec.files.map((path) => (base ? join(base, path) : path));
if (spec.files.length)
lines.push(
zh
diff --git a/packages/orchestration/src/conversations/groups/group-service.ts b/packages/orchestration/src/conversations/groups/group-service.ts
index d43632e..6e76749 100644
--- a/packages/orchestration/src/conversations/groups/group-service.ts
+++ b/packages/orchestration/src/conversations/groups/group-service.ts
@@ -448,7 +448,13 @@ export class GroupService implements CollaborationPort {
*/
resumeAfterPause(group: Group, announce: boolean) {
const resumed = this.workflows.pause.resume(group.id);
- if (announce && resumed.length) postProgramNotice(this, group, "resume", resumed[0]?.title);
+ if (announce && resumed.length)
+ postProgramNotice(
+ this,
+ group,
+ "resume",
+ resumed.map((step) => step.title),
+ );
return resumed;
}
private async updateNow(
diff --git a/packages/orchestration/src/conversations/groups/group-verdict-repair-plan.ts b/packages/orchestration/src/conversations/groups/group-verdict-repair-plan.ts
index c9be57f..7cf363c 100644
--- a/packages/orchestration/src/conversations/groups/group-verdict-repair-plan.ts
+++ b/packages/orchestration/src/conversations/groups/group-verdict-repair-plan.ts
@@ -9,6 +9,16 @@ import type { GroupWorkflowStepRecord } from "@pibot/storage";
import type { WorkflowProgress } from "./group-workflow-progress.ts";
import { implementationOwners, repairableVerdicts } from "./group-workflow-verdicts.ts";
+function withRoundSuffix(path: string, suffix: string) {
+ const slash = path.lastIndexOf("/");
+ const directory = slash === -1 ? "" : path.slice(0, slash + 1);
+ const name = slash === -1 ? path : path.slice(slash + 1);
+ const dot = name.lastIndexOf(".");
+ const stem = dot > 0 ? name.slice(0, dot) : name;
+ const extension = dot > 0 ? name.slice(dot) : "";
+ return `${directory}${stem}.${suffix}${extension}`;
+}
+
type Step = GroupPlan["steps"][number];
function upstream(
@@ -33,8 +43,11 @@ function upstream(
}
}
-function outputCopies(step: Step, prefix: string) {
- return step.deliverables.map((item) => ({ ...item, path: `${prefix}/${item.path}` }));
+function outputCopies(step: Step, suffix: string) {
+ return step.deliverables.map((item) => ({
+ ...item,
+ path: withRoundSuffix(item.path, suffix),
+ }));
}
export function verdictRepairPlan(
@@ -65,7 +78,11 @@ export function verdictRepairPlan(
const fixId = `${prefix}_fix`,
recheckId = `${prefix}_check`;
const implementation = upstream(original, before, author, owners);
- const summary = { id: "summary", path: `${prefix}/changes.md`, kind: "md" as const };
+ const summary = {
+ id: "summary",
+ path: withRoundSuffix("changes.md", prefix),
+ kind: "md" as const,
+ };
const facts: GroupVerification | undefined = progress.implementation;
const task = [
"修复原交付成果,不要修改核对结论冒充修复;按原合同交付修订成果。 / Repair the original artifacts and deliver their corrected versions under the original contract; never edit the verifier's verdict to fake a fix.",
@@ -73,7 +90,7 @@ export function verdictRepairPlan(
]
.join("\n")
.slice(0, 15000);
- const outputs = implementation ? outputCopies(implementation, `${prefix}/fixed`) : [summary];
+ const outputs = implementation ? outputCopies(implementation, prefix) : [summary];
steps.push({
id: fixId,
title: "修复不通过项 / Repair failed checks",
@@ -97,7 +114,7 @@ export function verdictRepairPlan(
stepId: fixId,
deliverableId: file.id,
})),
- deliverables: outputCopies(before, `${prefix}/recheck`),
+ deliverables: outputCopies(before, `${prefix}_recheck`),
task: `复验原不通过项和修订成果,给出真实结论。 / Recheck the failed items and corrected artifacts; give an honest verdict.\n${before.task}`.slice(
0,
15000,
diff --git a/packages/orchestration/src/conversations/groups/group-workflow-brief.ts b/packages/orchestration/src/conversations/groups/group-workflow-brief.ts
index f5bb912..3ddb189 100644
--- a/packages/orchestration/src/conversations/groups/group-workflow-brief.ts
+++ b/packages/orchestration/src/conversations/groups/group-workflow-brief.ts
@@ -49,7 +49,7 @@ export function stepInstructions(
`产物目录 / Output folder:\n${plan.folder}`,
ownWorkspace
? "你在自己的独立工作区里写,上面的路径相对于你的工作文件夹;通过检查后由 Pi Bot 合并回群文件夹。 / You write in your own workspace; the paths above are relative to your working folder. Pi Bot merges your work into the group folder once it passes its checks."
- : "",
+ : "你和其他成员在群文件夹里轮流写;上面的路径相对于群文件夹。 / You and the other members take turns writing in the group folder; the paths above are relative to that folder.",
handoffBrief(spec, plan.folder, "zh"),
`交付合同 / Delivery contract:\n${JSON.stringify({ deliverables: step.deliverables, acceptance: step.acceptance })}`,
dependencyContext ? `依赖上下文 / Dependency context:\n${dependencyContext}` : "",
diff --git a/packages/orchestration/src/conversations/groups/group-workflow-delivery-review.ts b/packages/orchestration/src/conversations/groups/group-workflow-delivery-review.ts
index d043933..bc8e3ae 100644
--- a/packages/orchestration/src/conversations/groups/group-workflow-delivery-review.ts
+++ b/packages/orchestration/src/conversations/groups/group-workflow-delivery-review.ts
@@ -225,7 +225,11 @@ export function supplementStep(before: GroupPlan, card: GroupPlanCard) {
}
export function reviewConclusion(review: DeliveryReview | undefined, zh: boolean) {
- if (!review?.coverage || review.unavailable)
+ if (
+ !review?.coverage ||
+ review.unavailable ||
+ review.coverage.length !== review.requirements.length
+ )
return [
zh
? "没有逐条核对原始需求是否都已覆盖:统筹的总结里没有可用的逐条对照。"
diff --git a/packages/orchestration/src/conversations/groups/group-workflow-status.ts b/packages/orchestration/src/conversations/groups/group-workflow-status.ts
index da73b1d..d3e3ef5 100644
--- a/packages/orchestration/src/conversations/groups/group-workflow-status.ts
+++ b/packages/orchestration/src/conversations/groups/group-workflow-status.ts
@@ -33,10 +33,17 @@ export function workflowStatusText(
const owner = (stepId: string) =>
names.get(steps.find((step) => step.stepId === stepId)?.ownerBotId ?? "") ?? "";
const done = steps.filter((step) => ["passed", "skipped"].includes(step.status));
- const running = steps.filter((step) => step.status === "running");
+ const running = steps.filter(
+ (step) => step.status === "running" && workspaces.get(step.stepId) !== "shared",
+ );
const held = new Set(Object.keys(progressOf(record).paused ?? {}));
const paused = steps.filter((step) => step.status === "ready" && held.has(step.stepId));
- const ready = steps.filter((step) => step.status === "ready" && !held.has(step.stepId));
+ const ready = steps.filter(
+ (step) =>
+ (step.status === "ready" ||
+ (step.status === "running" && workspaces.get(step.stepId) === "shared")) &&
+ !held.has(step.stepId),
+ );
const blocked = steps.filter((step) => step.status === "blocked");
const lines = [
zh
diff --git a/packages/workspaces/src/brain/groups/group-step-prepare.ts b/packages/workspaces/src/brain/groups/group-step-prepare.ts
index 1de2f34..62b957f 100644
--- a/packages/workspaces/src/brain/groups/group-step-prepare.ts
+++ b/packages/workspaces/src/brain/groups/group-step-prepare.ts
@@ -77,8 +77,10 @@ export async function prepareStepWorktree(
// Only the prepare limit is a setup failure; a stop or shutdown ends the step as before, and
// so does an approval nobody answered in time (that is the person's decision, not a setup).
const timedOut = signal.reason instanceof Error && signal.reason.name === "TimeoutError";
+ if (signal.aborted && timedOut && owner.stageOf(context.runId) === "authority")
+ throw new RpcError(-32602, "group_workspace_not_approved");
if (
- (signal.aborted && (!timedOut || owner.stageOf(context.runId) === "authority")) ||
+ (signal.aborted && !timedOut) ||
(error instanceof RpcError && DECISIONS.has(error.message))
)
throw error;