Агенты: менеджер отвечает за все работы проекта, включая подрядчиков (п.80); дубли todo: автоматические (агент и Claude) закрываются, ручные - с вопросом; правки Юрия в approved
Some checks failed
ci / test (push) Successful in 30s
ci / deploy (push) Failing after 3m36s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 20:46:31 +03:00
parent caec489563
commit ad8e65c15e
29 changed files with 258 additions and 33 deletions

View File

@@ -31,48 +31,49 @@ const COLS = `
coalesce((select array_agg(m.user_name order by m.user_name) from jt_task_assignment a
join jt_membership m on m.id = a.membership_id where a.task_id = t.id), '{}') as assignees`;
// Менеджер отвечает за ВСЕ работы своего проекта, включая подрядчиков (решение владельца 09.11.2026): отбор по проекту, а не по назначению на менеджера.
const MANAGER_TASKS = `
from jt_task t
join jt_task_assignment ma on ma.task_id = t.id and ma.membership_id = $2
where t.job_id = $1 and not t.is_deleted and not t.is_group and coalesce(t.progress, 0) < 1`;
/** Вход (1): не завершённые работы менеджера на этой неделе и просроченные. */
/** Вход (1): не завершённые работы проекта (в том числе подрядчиков) на этой неделе и просроченные. */
export async function input1(db: Queryable, p: InputParams): Promise<TaskRow[]> {
const { rows } = await db.query(
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and not t.is_todo
and t.end_date is not null and (t.end_date < $3 or (coalesce(t.start_date, t.end_date) <= $5 and t.end_date >= $4))
and t.end_date is not null and (t.end_date < $2 or (coalesce(t.start_date, t.end_date) <= $4 and t.end_date >= $3))
order by t.end_date, t.name`,
[p.jtJobId, p.managerMembershipId, p.today, p.weekStart, p.weekEnd],
[p.jtJobId, p.today, p.weekStart, p.weekEnd],
);
return rows;
}
/** Вход (2): todo менеджера на этой неделе и просроченные. */
/** Вход (2): todo проекта на этой неделе и просроченные. */
export async function input2(db: Queryable, p: InputParams): Promise<TaskRow[]> {
const { rows } = await db.query(
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and t.is_todo
and coalesce(t.end_date, t.start_date) is not null
and (coalesce(t.end_date, t.start_date) < $3 or coalesce(t.end_date, t.start_date) between $4 and $5)
and (coalesce(t.end_date, t.start_date) < $2 or coalesce(t.end_date, t.start_date) between $3 and $4)
order by coalesce(t.end_date, t.start_date), t.name`,
[p.jtJobId, p.managerMembershipId, p.today, p.weekStart, p.weekEnd],
[p.jtJobId, p.today, p.weekStart, p.weekEnd],
);
return rows;
}
/** Вход (3): todo менеджера на следующую неделю. */
/** Вход (3): todo проекта на следующую неделю. */
export async function input3(db: Queryable, p: InputParams): Promise<TaskRow[]> {
const { rows } = await db.query(
`select ${COLS}, null::text as related_task_id ${MANAGER_TASKS} and t.is_todo
and coalesce(t.end_date, t.start_date) between $3 and $4
and coalesce(t.end_date, t.start_date) between $2 and $3
order by coalesce(t.end_date, t.start_date), t.name`,
[p.jtJobId, p.managerMembershipId, p.nextWeekStart, p.nextWeekEnd],
[p.jtJobId, p.nextWeekStart, p.nextWeekEnd],
);
return rows;
}
// Остальные работы цепочки: все работы проекта, кроме уже попавших во входы (1) и (2) ($2 - их id).
const OTHERS = `
where t.job_id = $1 and not t.is_deleted and not t.is_group and coalesce(t.progress, 0) < 1
and not exists (select 1 from jt_task_assignment a where a.task_id = t.id and a.membership_id = $2)`;
and t.id <> all($2::text[])`;
/**
* Вход (4): работы других исполнителей (особенно закупки), зависящие (прямо или через цепочку до 5 звеньев)
@@ -82,15 +83,15 @@ export async function input4(db: Queryable, p: InputParams, managerTaskIds: stri
if (!managerTaskIds.length) return [];
const { rows } = await db.query(
`with recursive dep(root, id, depth) as (
select s, d.task_id, 1 from unnest($3::text[]) s join jt_task_dependency d on d.depends_on_task_id = s
select s, d.task_id, 1 from unnest($2::text[]) s join jt_task_dependency d on d.depends_on_task_id = s
union all
select dep.root, d.task_id, dep.depth + 1 from dep join jt_task_dependency d on d.depends_on_task_id = dep.id where dep.depth < 5
)
select distinct on (t.id) ${COLS}, dep.root as related_task_id
from dep join jt_task t on t.id = dep.id ${OTHERS}
and coalesce(t.start_date, t.end_date) is not null and coalesce(t.start_date, t.end_date) <= $4
and coalesce(t.start_date, t.end_date) is not null and coalesce(t.start_date, t.end_date) <= $3
order by t.id, dep.depth`,
[p.jtJobId, p.managerMembershipId, managerTaskIds, p.horizon],
[p.jtJobId, managerTaskIds, p.horizon],
);
return rows.sort((a, b) => String(a.start_date ?? a.end_date).localeCompare(String(b.start_date ?? b.end_date)) || a.name.localeCompare(b.name));
}
@@ -100,14 +101,14 @@ export async function input5(db: Queryable, p: InputParams, managerTaskIds: stri
if (!managerTaskIds.length) return [];
const { rows } = await db.query(
`with recursive dep(root, id, depth) as (
select s, d.depends_on_task_id, 1 from unnest($3::text[]) s join jt_task_dependency d on d.task_id = s
select s, d.depends_on_task_id, 1 from unnest($2::text[]) s join jt_task_dependency d on d.task_id = s
union all
select dep.root, d.depends_on_task_id, dep.depth + 1 from dep join jt_task_dependency d on d.task_id = dep.id where dep.depth < 5
)
select distinct on (t.id) ${COLS}, dep.root as related_task_id
from dep join jt_task t on t.id = dep.id ${OTHERS}
order by t.id, dep.depth`,
[p.jtJobId, p.managerMembershipId, managerTaskIds],
[p.jtJobId, managerTaskIds],
);
return rows.sort((a, b) => String(a.end_date ?? a.start_date).localeCompare(String(b.end_date ?? b.start_date)) || a.name.localeCompare(b.name));
}

View File

@@ -86,13 +86,13 @@ d("подготовка данных ассистента (временная Б
const items = await itemsOf("morning");
const ids = (no: number) => items.filter((i) => i.input_no === no).map((i) => i.jt_task_id);
expect(ids(1)).toEqual(["t-overdue", "t-week"]); // просроченное и на этой неделе; без будущего, завершённого и чужого проекта
expect(ids(1)).toEqual(["t-overdue", "t-week", "v-permit"]); // просроченное и на этой неделе, включая работы подрядчиков (менеджер отвечает за весь проект); без будущего, завершённого и чужого проекта
expect(items.find((i) => i.jt_task_id === "t-overdue")!.is_overdue).toBe(true);
expect(ids(2)).toEqual(["todo-over", "todo-week"]);
expect(ids(3)).toEqual(["todo-next"]);
expect(ids(4)).toEqual(["p-soon"]); // закупка через 4 рабочих дня; далёкая (2027) не входит
expect(items.find((i) => i.jt_task_id === "p-soon")).toMatchObject({ is_purchase: true, related_task_id: "t-week", days_until_start: 4 });
expect(ids(5)).toEqual(["v-permit"]); // подрядчик, от которого зависит Foundation
expect(ids(5)).toEqual([]); // подрядчик v-permit, от которого зависит Foundation, уже во входе (1): во вход (5) попадают только работы вне (1) и (2)
expect(ids(7)).toEqual(["t-week"]); // история напоминаний
expect(r.projects[0]).toMatchObject({ agent: "ok" });

View File

@@ -209,12 +209,13 @@ describe("промты в docs модуля (p-*.md)", () => {
expect(ceo).toContain("v_activity_action");
});
it("открытые вопросы повторяются (блок памяти, не больше 2 повторов), дубли todo закрывает только агентский автор", () => {
it("открытые вопросы повторяются (блок памяти, не больше 2 повторов), автоматические дубли todo (агент или Claude менеджера) закрываются, ручные - с вопросом", () => {
for (const name of ["p-manager-dialog.md", "p-ceo-assistant.md"]) {
const t = loadPrompt(name, { media_dir: "/m" }, "proposed");
expect(t, name).toContain("`Открытые вопросы`");
expect(t, name).toContain("не больше 2 повторов");
expect(t, name).toContain("kind = 'todo_created'");
expect(t, name).toContain("is_manual = false");
expect(t, name).toContain("сам не закрывай");
}
expect(loadFragment("p-chat-events.md", "Напоминание 12:00", {}, "proposed")).toContain("Открытые вопросы");