PEP-149: old tests follow the new contract (no «agent ended its turn» message, ask_pm with options)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Асель 2026-11-16 11:33:55 +05:00
parent 11d6bbafdf
commit 0a5eff6485
8 changed files with 40 additions and 34 deletions

View File

@ -1,22 +1,22 @@
# Tasks: PEP-149 # Tasks: PEP-149
## 1. Ядро ## 1. Ядро
- [ ] 1.1 Миграция: `questions.msg_type`, `questions.default_option` - [x] 1.1 Миграция: `questions.msg_type`, `questions.default_option`
- [ ] 1.2 `core/questions.ts`: типы, `questionType`, условие «ждёт человека»; тип и вариант по умолчанию в `askPm` / `askPmProject` / `raiseSessionQuestion` - [x] 1.2 `core/questions.ts`: типы, `questionType`, условие «ждёт человека»; тип и вариант по умолчанию в `askPm` / `askPmProject` / `raiseSessionQuestion`
- [ ] 1.3 `sendReviewCard`: тип `done`, ссылка на результат обязательна - [x] 1.3 `sendReviewCard`: тип `done`, ссылка на результат обязательна
- [ ] 1.4 Событие `blocker` в «Событиях агентов» (`EVENT_TEXT`) - [x] 1.4 Событие `blocker` в «Событиях агентов» (`EVENT_TEXT`)
## 2. Агент ## 2. Агент
- [ ] 2.1 `turnEnd`: конец хода → `progress`, сессия `idle`; остановка по простою для `idle` - [x] 2.1 `turnEnd`: конец хода → `progress`, сессия `idle`; остановка по простою для `idle`
- [ ] 2.2 Платформа будит агента после зелёных проверок (один раз на коммит) - [x] 2.2 Платформа будит агента после зелёных проверок (один раз на коммит)
- [ ] 2.3 MCP: `ask_pm` с вариантами и вариантом по умолчанию, `report_blocker`, описание `report_progress` - [x] 2.3 MCP: `ask_pm` с вариантами и вариантом по умолчанию, `report_blocker`, описание `report_progress`
## 3. Веб и бот ## 3. Веб и бот
- [ ] 3.1 Веб: карточка без «Продолжай», вариант по умолчанию; «Ждут вашего ответа», `navCounts`, `/api/attention`, счётчики чатов — только question (+ done в счётчике) - [x] 3.1 Веб: карточка без «Продолжай», вариант по умолчанию; «Ждут вашего ответа», `navCounts`, `/api/attention`, счётчики чатов — только question (+ done в счётчике)
- [ ] 3.2 Бот: без «Продолжай», вариант по умолчанию, push и счётчик только для question/done; `list_inbox` удалённого MCP - [x] 3.2 Бот: без «Продолжай», вариант по умолчанию, push и счётчик только для question/done; `list_inbox` удалённого MCP
- [ ] 3.3 Переводы en/kk - [x] 3.3 Переводы en/kk
## 4. Правила, помощь, проверки ## 4. Правила, помощь, проверки
- [ ] 4.1 `template/RULES.md`, «Помощь», AGENTS.md — четыре типа - [x] 4.1 `template/RULES.md`, «Помощь», AGENTS.md — четыре типа
- [ ] 4.2 Тесты по сценариям (`agent-messages.test.ts`), правка старых тестов - [x] 4.2 Тесты по сценариям (`agent-messages.test.ts`), правка старых тестов
- [ ] 4.3 lint, typecheck, build, тесты; проверка экранов; память проекта - [ ] 4.3 lint, typecheck, build, тесты; проверка экранов; память проекта

View File

@ -42,17 +42,17 @@ describe("autonomous cycle", () => {
assert.equal((await core.getQuestion(db, review.id)).answer, "✅ Принято"); assert.equal((await core.getQuestion(db, review.id)).answer, "✅ Принято");
}); });
test("after two nudges in a row the PM is called; a human answer resets the counter", async () => { test("after two nudges in a row the turn ends as progress — the PM is not called (PEP-149); a human message resets the counter", async () => {
const p = await project({ const p = await project({
turns: [[{ mcp: "update_task", args: { task: "1", status: "in_progress" } }, { say: "шаг 1" }], [{ say: "шаг 2" }], [{ say: "застрял на шаге 3" }], [{ say: "понял" }]], turns: [[{ mcp: "update_task", args: { task: "1", status: "in_progress" } }, { say: "шаг 1" }], [{ say: "шаг 2" }], [{ say: "застрял на шаге 3" }], [{ say: "понял" }]],
}); });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
assert.match(q.text, /застрял на шаге 3/);
assert.equal(await nudges(sid), runner.MAX_AUTO_NUDGES); assert.equal(await nudges(sid), runner.MAX_AUTO_NUDGES);
await runner.answerAndDeliver(db, q.id, "делай вариант Б", "telegram"); assert.deepEqual(await p.pending(sid), [], "nobody is asked");
assert.equal((await p.session(sid)).autoNudges, 0); await runner.sendToSession(db, sid, "делай вариант Б");
await p.waitLog("answer delivered", (e) => e.ev === "prompt" && String(e.prompt).includes("вариант Б")); await p.waitLog("message delivered", (e) => e.ev === "prompt" && String(e.prompt).includes("вариант Б"));
await waitFor("the counter is reset", async () => (await p.session(sid)).autoNudges === 0);
await runner.stopSession(db, sid); await runner.stopSession(db, sid);
}); });
@ -71,7 +71,7 @@ describe("autonomous cycle", () => {
describe("task board", () => { describe("task board", () => {
test("moving a card to In progress starts an agent; back to Backlog stops it", async () => { test("moving a card to In progress starts an agent; back to Backlog stops it", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Стоппер?" } }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Стоппер?", options: ["Да", "Нет"], default: "Да" } }]] });
let ref = await core.resolveTask(db, p.taskKey); let ref = await core.resolveTask(db, p.taskKey);
assert.equal(runner.columnOf(ref.task.status), "backlog"); assert.equal(runner.columnOf(ref.task.status), "backlog");
const { started } = await runner.moveTask(db, ref, "in_progress"); const { started } = await runner.moveTask(db, ref, "in_progress");

View File

@ -79,7 +79,7 @@ describe("pairing", () => {
describe("answering from Telegram", () => { describe("answering from Telegram", () => {
test("question with options: button press reaches the agent, message is closed", async () => { test("question with options: button press reaches the agent, message is closed", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Какую БД взять?", options: ["Postgres", "SQLite"] } }, { say: "Жду." }], [{ say: "Ок." }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Какую БД взять?", options: ["Postgres", "SQLite"], default: "Postgres" } }, { say: "Жду." }], [{ say: "Ок." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
const m = await messageFor(q.id); const m = await messageFor(q.id);
@ -138,7 +138,9 @@ describe("answering from Telegram", () => {
test("free-text reply to a 'session is waiting' alert is typed into the session", async () => { test("free-text reply to a 'session is waiting' alert is typed into the session", async () => {
const p = await project({ turns: [[{ say: "Сделал черновик. Что дальше?" }], [{ say: "Понял." }]] }); const p = await project({ turns: [[{ say: "Сделал черновик. Что дальше?" }], [{ say: "Понял." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
// PEP-149: the end of a turn asks nobody — a message of the factory stands in for the old alert.
const q = await core.raiseSessionQuestion(db, await p.session(sid), "attention", "Сделал черновик. Что дальше?");
const m = await messageFor(q.id); const m = await messageFor(q.id);
assert.match(m.text, /Что дальше/); assert.match(m.text, /Что дальше/);
tg.userSends(PM, "добавь тесты\nи README", m.message_id); tg.userSends(PM, "добавь тесты\nи README", m.message_id);
@ -154,7 +156,7 @@ describe("several users", () => {
await waitFor("bob paired", async () => (await core.getUser(db, bobUser.id))?.telegramChatId === BOB.chatId); await waitFor("bob paired", async () => (await core.getUser(db, bobUser.id))?.telegramChatId === BOB.chatId);
// PM's project: Bob has no access. // PM's project: Bob has no access.
const mine = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Секрет проекта PM?", options: ["Да", "Нет"] } }], [{ say: "Ок." }]] }); const mine = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Секрет проекта PM?", options: ["Да", "Нет"], default: "Да" } }], [{ say: "Ок." }]] });
const sid = await mine.start(); const sid = await mine.start();
const q = await mine.waitQuestion(sid, "question"); const q = await mine.waitQuestion(sid, "question");
const m = await messageFor(q.id); const m = await messageFor(q.id);
@ -198,7 +200,7 @@ describe("review", () => {
describe("staleness and reliability", () => { describe("staleness and reliability", () => {
test("answered in the terminal: Telegram message is closed and old buttons do nothing", async () => { test("answered in the terminal: Telegram message is closed and old buttons do nothing", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Порт сервиса?", options: ["8080", "3000"] } }], [{ say: "Ок." }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Порт сервиса?", options: ["8080", "3000"], default: "8080" } }], [{ say: "Ок." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
const m = await messageFor(q.id); const m = await messageFor(q.id);
@ -213,7 +215,9 @@ describe("staleness and reliability", () => {
test("an update re-delivered after a restart is not replayed", async () => { test("an update re-delivered after a restart is not replayed", async () => {
const p = await project({ turns: [[{ say: "Жду указаний." }], [{ say: "Ок." }], [{ say: "лишний ход" }]] }); const p = await project({ turns: [[{ say: "Жду указаний." }], [{ say: "Ок." }], [{ say: "лишний ход" }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
// PEP-149: the end of a turn asks nobody — a message of the factory stands in for the old alert.
const q = await core.raiseSessionQuestion(db, await p.session(sid), "attention", "Жду указаний.");
const m = await messageFor(q.id); const m = await messageFor(q.id);
const updateId = tg.userSends(PM, "сделай раз", m.message_id); const updateId = tg.userSends(PM, "сделай раз", m.message_id);
await p.waitLog("delivered once", isPrompt("сделай раз")); await p.waitLog("delivered once", isPrompt("сделай раз"));
@ -227,7 +231,7 @@ describe("staleness and reliability", () => {
test("outbox retries after 429 (retry_after) and 5xx", async () => { test("outbox retries after 429 (retry_after) and 5xx", async () => {
tg.failNext("sendMessage", 429, 1); tg.failNext("sendMessage", 429, 1);
tg.failNext("sendMessage", 500); tg.failNext("sendMessage", 500);
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Проверка ретраев?" } }], [{ say: "Ок." }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Проверка ретраев?", options: ["Да", "Нет"], default: "Да" } }], [{ say: "Ок." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
const m = await messageFor(q.id); const m = await messageFor(q.id);
@ -259,7 +263,7 @@ describe("staleness and reliability", () => {
}); });
test("tmux killed while waiting: answer is saved, PM told the session is down", async () => { test("tmux killed while waiting: answer is saved, PM told the session is down", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Что с API?" } }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Что с API?", options: ["Да", "Нет"], default: "Да" } }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
const m = await messageFor(q.id); const m = await messageFor(q.id);

View File

@ -21,7 +21,7 @@ const budgetQuestion = (taskId: number) =>
async function spentRunner() { async function spentRunner() {
const p = await project({ turns: [[{ usage: { input: 1000, output: 500 } }, { say: "Сделал часть." }]] }); const p = await project({ turns: [[{ usage: { input: 1000, output: 500 } }, { say: "Сделал часть." }]] });
const sid = await p.start(); const sid = await p.start();
await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
await waitFor("usage recorded", async () => core.usageTotals((await core.getSession(db, sid)).usage).total === 1500); await waitFor("usage recorded", async () => core.usageTotals((await core.getSession(db, sid)).usage).total === 1500);
return { p, sid, task: await p.task() }; return { p, sid, task: await p.task() };
} }

View File

@ -76,7 +76,7 @@ describe("Claude: task lifecycle", () => {
describe("Claude: questions to the PM", () => { describe("Claude: questions to the PM", () => {
test("ask_pm question answered from Telegram is typed into the session", async () => { test("ask_pm question answered from Telegram is typed into the session", async () => {
const p = await project({ const p = await project({
turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Какую БД взять?", options: ["Postgres", "SQLite"] } }, { say: "Жду ответа." }], [{ say: "Беру Postgres." }]], turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Какую БД взять?", options: ["Postgres", "SQLite"], default: "Postgres" } }, { say: "Жду ответа." }], [{ say: "Беру Postgres." }]],
}); });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
@ -90,7 +90,9 @@ describe("Claude: questions to the PM", () => {
test("multi-line answer arrives as one prompt (bracketed paste)", async () => { test("multi-line answer arrives as one prompt (bracketed paste)", async () => {
const p = await project({ turns: [[{ say: "Что дальше?" }], [{ say: "Понял." }]] }); const p = await project({ turns: [[{ say: "Что дальше?" }], [{ say: "Понял." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
// PEP-149: the end of a turn asks nobody — a message of the factory stands in for the old alert.
const q = await core.raiseSessionQuestion(db, await p.session(sid), "attention", "Что дальше?");
await runner.answerAndDeliver(db, q.id, "строка один\nстрока два", PM); await runner.answerAndDeliver(db, q.id, "строка один\nстрока два", PM);
const e = await p.waitLog("pasted prompt", isPrompt("строка один")); const e = await p.waitLog("pasted prompt", isPrompt("строка один"));
assert.equal(e.prompt, "строка один\nстрока два"); assert.equal(e.prompt, "строка один\nстрока два");
@ -127,7 +129,7 @@ describe("Claude: questions to the PM", () => {
}); });
test("typing in the terminal answers whatever the session was waiting for", async () => { test("typing in the terminal answers whatever the session was waiting for", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Название сервиса?" } }], [{ say: "Ок." }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "1", question: "Название сервиса?", options: ["Да", "Нет"], default: "Да" } }], [{ say: "Ок." }]] });
const sid = await p.start(); const sid = await p.start();
const q = await p.waitQuestion(sid, "question"); const q = await p.waitQuestion(sid, "question");
await runner.sendToSession(db, sid, "назови peppa-api"); await runner.sendToSession(db, sid, "назови peppa-api");

View File

@ -90,9 +90,9 @@ describe("Защита от зацикливания", () => {
test("Предел достигнут", async () => { test("Предел достигнут", async () => {
const p = await project({ turns: [[{ say: "работаю" }], [{ limit: { resetInSec: 120 } }]] }); const p = await project({ turns: [[{ say: "работаю" }], [{ limit: { resetInSec: 120 } }]] });
const sid = await p.start(); const sid = await p.start();
await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
await core.updateSession(db, sid, { limitResumes: runner.MAX_LIMIT_RESUMES_PER_DAY, limitResumesDay: new Date().toLocaleDateString("sv-SE") }); await core.updateSession(db, sid, { limitResumes: runner.MAX_LIMIT_RESUMES_PER_DAY, limitResumesDay: new Date().toLocaleDateString("sv-SE") });
await runner.answerAndDeliver(db, (await p.waitQuestion(sid, "attention")).id, "дальше", "web"); await runner.sendToSession(db, sid, "дальше");
await p.waitStatus(sid, "rate_limited"); await p.waitStatus(sid, "rate_limited");
const s = await sess(sid); const s = await sess(sid);
assert.equal(s.resumeAt, null, "no more auto-resumes today"); assert.equal(s.resumeAt, null, "no more auto-resumes today");

View File

@ -94,7 +94,7 @@ async function mcpAs(user: typeof owner) {
describe("PM tools over MCP", () => { describe("PM tools over MCP", () => {
test("list, create, move (starts an agent), inbox, answer; strangers see nothing", async () => { test("list, create, move (starts an agent), inbox, answer; strangers see nothing", async () => {
const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "2", question: "Какой порт?", options: ["8080", "3000"] } }], [{ say: "Ок." }]] }); const p = await project({ turns: [[{ mcp: "ask_pm", args: { task: "2", question: "Какой порт?", options: ["8080", "3000"], default: "8080" } }], [{ say: "Ок." }]] });
const proj = await core.getProject(db, p.key); const proj = await core.getProject(db, p.key);
await core.setProjectOwner(db, proj.id, owner.id); await core.setProjectOwner(db, proj.id, owner.id);
const { client, call } = await mcpAs(owner); const { client, call } = await mcpAs(owner);

View File

@ -56,7 +56,7 @@ describe("Расход сессии из statusLine и transcript", () => {
const p = await project({ turns: [[{ usage: { input: 1200, output: 300, costUsd: 0.42, context: { used: 50000, size: 200000 }, fiveHour: 42, sevenDay: 18 } }, { say: "Готово." }]] }); const p = await project({ turns: [[{ usage: { input: 1200, output: 300, costUsd: 0.42, context: { used: 50000, size: 200000 }, fiveHour: 42, sevenDay: 18 } }, { say: "Готово." }]] });
const sid = await p.start(); const sid = await p.start();
await p.waitLog("statusline", (e) => e.ev === "statusline"); await p.waitLog("statusline", (e) => e.ev === "statusline");
await p.waitQuestion(sid, "attention"); await p.waitStatus(sid, "idle");
const s = await core.getSession(db, sid); const s = await core.getSession(db, sid);
const t = core.usageTotals(s.usage); const t = core.usageTotals(s.usage);
assert.equal(t.total, 1500); assert.equal(t.total, 1500);