peppa/apps/web/components/Autonomy.tsx
Асель 9052f3245f Merge main into task/pep-98: PEP-112…124 texts through the dictionary
Main's new wording (PEP-123 «Продакт» words) kept and wrapped in t()/m();
wording(mode, locale) gives English words for {task}/{runner} placeholders;
glossary check (pnpm lint) passes; English for all new keys (en/merge-*.ts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:04:39 +05:00

95 lines
5.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// PEP-23: project autonomy in «⋯ Настройки проекта» — preset levels and the individual settings.
import { AUTONOMY_LEVEL_HINT, AUTONOMY_LEVEL_RU, AUTONOMY_LEVELS, autonomyLevel, type AutonomyLevel, type AutonomySettings } from "@peppa/core";
import { setAutonomyAction } from "@/app/(app)/actions";
import { Hidden } from "@/components/cards";
import { Button } from "@/components/ui/button";
import { Input, Label, NativeSelect } from "@/components/ui/input";
import { getT } from "@/lib/i18n";
export async function AutonomyPanel({ projectId, settings, back, engineer = false }: { projectId: number; settings: AutonomySettings; back: string; /** PEP-123: the detailed settings speak of merges and pipelines — «Инженер» only. */ engineer?: boolean }) {
const t = await getT();
const current = autonomyLevel(settings);
const s = settings;
return (
<div className="flex flex-col gap-3">
<div className="flex flex-wrap gap-2" role="group" aria-label={t("Уровень автономности")}>
{(Object.keys(AUTONOMY_LEVELS) as AutonomyLevel[]).map((level) => (
<form key={level} action={setAutonomyAction}>
<Hidden fields={{ projectId, level, back }} />
<Button size="sm" variant={current === level ? "default" : "outline"} aria-pressed={current === level} title={t.text(AUTONOMY_LEVEL_HINT[level])}>
{t.text(AUTONOMY_LEVEL_RU[level])}
</Button>
</form>
))}
{current === "custom" && (
<Button size="sm" variant="default" disabled aria-pressed>
{t.text(AUTONOMY_LEVEL_RU.custom)}
</Button>
)}
</div>
<p className="m-0 text-xs text-muted-foreground">{current === "custom" ? t("Своя комбинация настроек ниже.") : t.text(AUTONOMY_LEVEL_HINT[current])}</p>
{engineer && (
<details>
<summary className="cursor-pointer text-sm text-primary">{t("Настроить подробно")}</summary>
<form action={setAutonomyAction} className="mt-3 flex flex-col gap-3">
<Hidden fields={{ projectId, back }} />
<Label>
{t("Кто берёт стори из бэклога")}
<NativeSelect name="pick" defaultValue={s.pick} className="h-8">
<option value="pm">{t("PM — двигает карточки сам")}</option>
<option value="auto">{t("Peppa FACTORY — сама, по порядку на доске")}</option>
</NativeSelect>
</Label>
<Label>
{t("Сколько стори в работе одновременно (для «Peppa FACTORY сама»)")}
<Input name="wipLimit" type="number" min={1} max={5} defaultValue={s.wipLimit} className="h-8" />
</Label>
<Label>
{t("План стори")}
<NativeSelect name="proposal" defaultValue={s.proposal} className="h-8">
<option value="agent">{t("Агент составляет и сразу делает — без вашего одобрения")}</option>
<option value="pm">{t("Вы одобряете план каждой стори")}</option>
</NativeSelect>
</Label>
<Label>
{t("Мерж PR")}
<NativeSelect name="merge" defaultValue={s.merge} className="h-8">
<option value="manual">{t("По кнопке «Принять»")}</option>
<option value="auto">{t("Сам после зелёных проверок и без конфликтов")}</option>
</NativeSelect>
</Label>
<Label>
{t("Закрытие стори")}
<NativeSelect name="close" defaultValue={s.close} className="h-8">
<option value="pm">{t("PM принимает")}</option>
<option value="after_merge">{t("Сразу после мержа")}</option>
<option value="after_hours">{t("Само через N часов без замечаний")}</option>
</NativeSelect>
</Label>
<Label>
{t("N часов до автозакрытия")}
<Input name="closeAfterHours" type="number" min={1} max={336} defaultValue={s.closeAfterHours} className="h-8" />
</Label>
<label className="flex items-center gap-2 text-sm">
<input type="checkbox" name="idlePush" defaultChecked={s.idlePush} /> {t("Пуш, если агенты простаивают, а в бэклоге есть стори")}
</label>
<Label>
{t("Не чаще раза в (часов); столько же длится «Не сейчас»")}
<Input name="idlePushHours" type="number" min={1} max={168} defaultValue={s.idlePushHours} className="h-8" />
</Label>
<label className="flex items-center gap-2 text-sm">
<input type="checkbox" name="quiet" defaultChecked={s.quietFrom != null} /> {t("Тихие часы")}
</label>
<div className="flex items-center gap-2 text-sm">
{t("с")} <Input name="quietFrom" type="number" min={0} max={23} defaultValue={s.quietFrom ?? 22} className="h-8 w-20" aria-label={t("Тихие часы с")} />
{t("до")} <Input name="quietTo" type="number" min={0} max={23} defaultValue={s.quietTo ?? 9} className="h-8 w-20" aria-label={t("Тихие часы до")} />
</div>
<Button size="sm" className="self-start">{t("Сохранить")}</Button>
</form>
</details>
)}
{engineer && <p className="m-0 text-xs text-muted-foreground">{t("PR, меняющий конвейер (.gitea/, checks, deploy), сам не мержится и не закрывается — его принимает PM.")}</p>}
</div>
);
}