import { randomUUID } from "node:crypto"; import * as fs from "node:fs"; import * as path from "node:path"; import type { ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent"; import { cleanupTeamDir, gcStaleTeamDirs } from "./cleanup.js"; import { writeToMailbox } from "./mailbox.js"; import { sanitizeName } from "./names.js"; import { getTeamDir, getTeamsRootDir, getTeamsStylesDir } from "./paths.js"; import { TEAM_MAILBOX_NS } from "./protocol.js"; import { unassignTasksForAgent, type TeamTask } from "./task-store.js"; import { setMemberStatus, setTeamStyle, type TeamConfig } from "./team-config.js"; import { type TeamsStyle, formatMemberDisplayName, getTeamsStrings, listAvailableTeamsStyles, normalizeTeamsStyleId, resolveTeamsStyleDefinition, formatTeamsTemplate, } from "./teams-style.js"; import type { TeammateRpc } from "./teammate-rpc.js"; export async function handleTeamDelegateCommand(opts: { ctx: ExtensionCommandContext; rest: string[]; getDelegateMode: () => boolean; setDelegateMode: (next: boolean) => void; renderWidget: () => void; }): Promise { const { ctx, rest, getDelegateMode, setDelegateMode, renderWidget } = opts; const arg = rest[0]; if (arg === "on") setDelegateMode(true); else if (arg === "off") setDelegateMode(false); else setDelegateMode(!getDelegateMode()); ctx.ui.notify(`Delegate mode ${getDelegateMode() ? "ON" : "OFF"}`, "info"); renderWidget(); } export async function handleTeamStyleCommand(opts: { ctx: ExtensionCommandContext; rest: string[]; teamDir: string; getStyle: () => TeamsStyle; setStyle: (next: TeamsStyle) => void; refreshTasks: () => Promise; renderWidget: () => void; }): Promise { const { ctx, rest, teamDir, getStyle, setStyle, refreshTasks, renderWidget } = opts; const argRaw = rest[0]; if (!argRaw) { ctx.ui.notify( "Teams style:\n" + ` current: ${getStyle()}\n` + " list: /team style list\n" + " set: /team style \n" + " init: /team style init [extends ]", "info", ); return; } if (argRaw === "list") { const { dir, all, builtins, customs } = listAvailableTeamsStyles(); ctx.ui.notify( [ "Available team styles:", "", `built-in: ${builtins.join(", ")}`, customs.length ? `custom: ${customs.join(", ")}` : "custom: (none)", "", "To add a custom style, create a JSON file:", ` ${dir}/