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.
TypeScript agentai-agentai-agentsai-assistantandroidautomationchatgptcoding-agentcomputer-usedesktop-appelectronllmlocal-firstmcpmulti-agentollamaopenaiprivacyself-hostedtypescript
fix(groups): project files are edited in place, and an unapplied plan change says so
leen.zhoue8ff53cec98a
diff --git a/packages/orchestration/src/conversations/groups/group-plan-delivery.ts b/packages/orchestration/src/conversations/groups/group-plan-delivery.tsindex 8eb4ae2..cac2db2 100644--- a/packages/orchestration/src/conversations/groups/group-plan-delivery.ts+++ b/packages/orchestration/src/conversations/groups/group-plan-delivery.ts@@ -12,6 +12,7 @@ import {type PlanDelivery,SkillContractSchema,} from "@pibot/protocol-base";+import { isCodeFile } from "./group-verification-facts.ts";const period = /^\d{4}-(?:\d{2}-\d{2}|W\d{2}|\d{2})(?:-\d{1,3})?$/;@@ -67,6 +68,45 @@ export function relativeDeliveryPath(return canonicalPath(path, name, folder, paths);}+/**+ * Windows acceptance 2026-11-21: a plan to fix calc.ps1 listed calc.ps1 and test.ps1 as the+ * implement step's deliverables. Deliverables are always written into the output folder, so the+ * member wrote fixed copies there and the project's own calc.ps1 never changed. A source file+ * that exists in the working folder, or sits in one of its existing folders, is the project's:+ * the step edits it in place and delivers a change note instead.+ */+async function projectSource(+ path: string,+ workspaceRoot: string,+ access: WorkspaceFileAccess,+ signal: AbortSignal,+) {+ const { resolve, dirname } = access.paths;+ if (!isCodeFile(path, access.paths)) return false;+ const kind = async (target: string) => {+ try {+ return (await access.probe(target, signal))?.kind;+ } catch (error) {+ if (signal.aborted) throw error;+ // Best effort: a folder the probe cannot read (an older runner) keeps the plan as written.+ return undefined;+ }+ };+ if ((await kind(resolve(workspaceRoot, path))) === "file") return true;+ const parent = dirname(path);+ return parent !== "." && (await kind(resolve(workspaceRoot, parent))) === "directory";+}++function projectSourceIssue(path: string, at: (string | number)[]) {+ return {+ code: "plan_deliverable_project_file",+ path: at,+ expected:+ "A new artifact such as 改动说明.md; project files are edited in place / 新产物,如 改动说明.md;项目文件原地修改",+ message: `「${path}」是工作文件夹里的项目文件。交付物只会写进产物目录,列它只会得到一份副本,项目本身不变。请在 task 里写明直接修改项目里的这个文件(新增的源码和测试也直接写进项目),交付物改为改动说明,例如 改动说明.md。 / ${path} is a project file in the working folder. Deliverables are written only to the output folder, so listing it yields a copy and leaves the project unchanged. Say in task to edit this project file in place (write new source and test files into the project too) and list a change note such as 改动说明.md as the deliverable.`,+ };+}+/** Plan validation chooses without creating directories, so confirmation and execution refer to one folder. */export async function preparePlanDelivery(value: unknown,@@ -74,10 +114,12 @@ export async function preparePlanDelivery(signal: AbortSignal,previous?: PlanDelivery,access?: WorkspaceFileAccess,+ /** Passed or skipped steps of the plan being replaced: their accepted contract is kept as is. */+ completed: ReadonlySet<string> = new Set(),): Promise<{value: unknown;delivery?: PlanDelivery;- issues?: { code: string; path: (string | number)[]; expected: string }[];+ issues?: { code: string; path: (string | number)[]; expected: string; message?: string }[];}> {const { relative, isAbsolute, sep } = access?.paths ?? pathApi;signal.throwIfAborted();@@ -113,7 +155,8 @@ export async function preparePlanDelivery(return wrongRoot();const delivery: PlanDelivery = { workspaceRoot, folder: place.folder, rewrites: [] };signal.throwIfAborted();- const issues: { code: string; path: (string | number)[]; expected: string }[] = [];+ const issues: { code: string; path: (string | number)[]; expected: string; message?: string }[] =+ [];const steps = input.steps.map((step, index) => ({...step,deliverables: step.deliverables.map((item, n) => {@@ -137,6 +180,19 @@ export async function preparePlanDelivery(return { ...item, path };}),}));+ if (access && !issues.length) {+ const checks = steps.flatMap((step, index) =>+ completed.has(step.id)+ ? []+ : step.deliverables.map(async (item, n) =>+ (await projectSource(item.path, workspaceRoot, access, signal))+ ? projectSourceIssue(item.path, ["steps", index, "deliverables", n, "path"])+ : undefined,+ ),+ );+ for (const issue of await Promise.all(checks)) if (issue) issues.push(issue);+ signal.throwIfAborted();+ }const key = (stepId: string, id: string) => `${stepId}/${id}`;const paths = new Map(steps.flatMap((step) =>diff --git a/packages/orchestration/src/conversations/groups/group-plan-supplement.ts b/packages/orchestration/src/conversations/groups/group-plan-supplement.tsindex 2fc6d70..120a67f 100644--- a/packages/orchestration/src/conversations/groups/group-plan-supplement.ts+++ b/packages/orchestration/src/conversations/groups/group-plan-supplement.ts@@ -45,6 +45,9 @@ export function planSupplement(cycleId: cycle.cycleId,note: [`本群的计划正在由程序执行。下面是用户在主对话里的补充或提问:回答进度、记下补充;不要重新提交计划或另行分派,计划会继续。 / The program is executing this group's plan. Below is the user's supplement or question: answer progress or note it; do not resubmit the plan or assign work. The plan continues.`,+ // Windows acceptance 2026-11-21: asked to make two steps sequential, the coordinator+ // resubmitted, got the running card back and claimed 「已修改并启动」.+ `用户要改计划(增删步骤、改顺序或分工)时,运行中的计划不能直接改:如实说明,请用户先在计划卡上或「任务」里点「停止计划」,再提出新要求;不要声称已修改。 / If the user asks to change the plan (add or remove steps, reorder, reassign), a running plan cannot be changed in place: say so and ask them to tap Stop plan on the plan card or under Tasks first, then make the new request; never claim it was changed.`,`计划进度(程序记录) / Plan progress (program facts): ${JSON.stringify(progress)}`,].join("\n"),};diff --git a/packages/orchestration/src/conversations/groups/group-plans.ts b/packages/orchestration/src/conversations/groups/group-plans.tsindex 4372baf..c70bf32 100644--- a/packages/orchestration/src/conversations/groups/group-plans.ts+++ b/packages/orchestration/src/conversations/groups/group-plans.ts@@ -28,6 +28,7 @@ import {GroupExecutionLimitsRepo,GroupPlansRepo,GroupVerificationRulesRepo,+ MessagesRepo,transaction,} from "@pibot/storage";import { planConfirmationRequired } from "./group-plan-confirmation.ts";@@ -58,6 +59,8 @@ export class GroupDynamicPlans {private engine?: GroupPlanEngine;private closed = false;private readonly jobs = new Map<string, Promise<GroupPlanCard>>();+ /** Runs already told, with a group line, that their plan submission changed nothing. */+ private readonly unchangedNotices = new Set<string>();constructor(private readonly service: GroupService) {this.repo = new GroupPlansRepo(service.deps.db);}@@ -225,7 +228,8 @@ export class GroupDynamicPlans {const recovered = await this.start(existing.message.id, signal);return { text: JSON.stringify({ status: recovered.status, planId: recovered.id }) };}- if (existing && !failed && (!replacing || existing.card.originRunId === context.runId))+ if (existing && !failed && (!replacing || existing.card.originRunId === context.runId)) {+ if (existing.card.originRunId !== context.runId) return this.unchanged(run, existing.card);return {text: JSON.stringify({status: existing.card.status,@@ -233,6 +237,7 @@ export class GroupDynamicPlans {...this.deliveryNote(existing.card),}),};+ }this.service.planAttempts.guard(context, "group_plan");if (this.service.planAttempts.remaining(context) === 0) {this.service.planAttempts.hold(context);@@ -253,6 +258,14 @@ export class GroupDynamicPlans {);input = retained.value;const members = this.members(group.id);+ const completed = new Set(+ replacing+ ? this.service.workflows.repo+ .steps(replacing.id)+ .filter((step) => step.status === "passed" || step.status === "skipped")+ .map((step) => step.stepId)+ : [],+ );const expanded = await expandPlanMethods(input,members,@@ -262,14 +275,7 @@ export class GroupDynamicPlans {return (keys ?? []).filter((key) => this.service.deps.redactor.redact(key) === key);},!!replacing,- new Set(- replacing- ? this.service.workflows.repo- .steps(replacing.id)- .filter((step) => step.status === "passed" || step.status === "skipped")- .map((step) => step.stepId)- : [],- ),+ completed,);if (!expanded.ok) return reject(expanded.issues);const workplace = await groupWorkplace(this.service.deps.local, context.botId, group, signal);@@ -288,6 +294,7 @@ export class GroupDynamicPlans {}): undefined,access,+ completed,);if (normalized.issues) return reject(normalized.issues);const agentReady = this.service.deps.local.externalAgentProvider?.stepReadiness;@@ -489,6 +496,52 @@ export class GroupDynamicPlans {this.changed(saved.id, card);await this.start(saved.id, signal);}+ /**+ * Windows acceptance 2026-11-21: the user asked to re-plan a running plan's test and review as+ * sequential steps; the coordinator called group_plan, got this cycle's running card back as+ * {status:"started"} with "registered and scheduling steps", and told the user 「已按你的要求修改+ * 并启动」 while nothing had changed. A later run's submission never replaces the cycle's plan, so+ * the result says so as a failure, and a run answering the user's own message also gets a fixed+ * program line, so the user learns the truth even if the reply claims otherwise.+ */+ private unchanged(run: Run, card: GroupPlanCard): LocalToolResult {+ const waiting = card.status === "pending" || card.status === "ready";+ if (run.kind === "chat" && !this.unchangedNotices.has(run.id)) {+ if (this.unchangedNotices.size >= 200) this.unchangedNotices.clear();+ this.unchangedNotices.add(run.id);+ const group = this.service.groups.get(card.groupId);+ const zh = this.service.deps.chat.currentLanguage() === "zh";+ if (group) {+ new MessagesRepo(this.service.deps.db).create({+ conversationId: group.conversationId,+ botId: group.coordinatorBotId,+ role: "assistant",+ content: waiting+ ? zh+ ? "计划没有改动:计划卡还在等你点「开始」或「修改」。要改计划,请点卡片上的「修改」。"+ : "The plan was not changed: its card is still waiting for Start or Modify. To change the plan, tap Modify on the card."+ : zh+ ? "计划没有改动:正在进行的计划不会被新提交替换。要改步骤,请先在计划卡上或「任务」里点「停止计划」,再说要怎么改。"+ : "The plan was not changed: a running plan is never replaced by a new submission. To change its steps, tap Stop plan on the plan card or under Tasks first, then say how to change it.",+ status: "done",+ usage: { groupProgramNotice: { kind: "plan_unchanged" } },+ });+ this.service.changed(group.id, "updated");+ }+ }+ return {+ isError: true,+ text: JSON.stringify({+ code: "group_plan_unchanged",+ changed: false,+ status: card.status,+ planId: card.id,+ instruction: waiting+ ? "本次提交没有生效:本轮的计划卡仍在等用户点「开始 / 修改」,程序没有改它。不要说已修改或已开始;如实告诉用户计划没变,要改请点卡片上的「修改」。 / This submission did not take effect: this round's plan card still awaits the user's Start / Modify and the program did not change it. Do not claim it was changed or started; tell the user the plan is unchanged and that Modify on the card changes it."+ : "本次提交没有生效:本轮已有计划在执行(或已登记),程序没有修改、替换或重新开始它,原计划照旧进行。不要说已修改或已重新启动;如实告诉用户计划没变,要改步骤须先在计划卡上或「任务」里点「停止计划」,再提出新要求。 / This submission did not take effect: this round's plan is already running (or registered) and the program did not change, replace or restart it; the original plan continues. Do not claim it was changed or restarted; tell the user the plan is unchanged and that changing its steps needs Stop plan on the plan card or under Tasks first, then a new request.",+ }),+ };+ }/** Repairs are already applied to the saved plan; repeating them only wastes attempts. */private correctionNote(corrections: string[]) {return corrections.lengthdiff --git a/packages/orchestration/src/conversations/groups/group-verification-facts.ts b/packages/orchestration/src/conversations/groups/group-verification-facts.tsindex 94bde7c..df589f2 100644--- a/packages/orchestration/src/conversations/groups/group-verification-facts.ts+++ b/packages/orchestration/src/conversations/groups/group-verification-facts.ts@@ -73,11 +73,15 @@ export function changedCodeFiles(root: string,isolated?: Isolated,) {- return changedFiles(rows, paths, root, isolated).filter(- (file) =>- CODE.has(paths.extname(file).toLowerCase()) ||- BUILD.has(paths.basename(file).toLowerCase()) ||- /\.(?:html?|ipynb)$/iu.test(file),+ return changedFiles(rows, paths, root, isolated).filter((file) => isCodeFile(file, paths));+}++/** Source, build and page files: what a code change touches, as opposed to a document. */+export function isCodeFile(file: string, paths: Pick<Paths, "extname" | "basename">) {+ return (+ CODE.has(paths.extname(file).toLowerCase()) ||+ BUILD.has(paths.basename(file).toLowerCase()) ||+ /\.(?:html?|ipynb)$/iu.test(file));}