Compare commits
11 Commits
fix/1117-j
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 976e8ebe2d | |||
| c934a6be44 | |||
| f0925982c9 | |||
| cfbeb582fa | |||
| 4550c4132a | |||
| 294833ccc5 | |||
| f48579d574 | |||
| c5a605ab1d | |||
| 517b3ee844 | |||
| 75aa931f85 | |||
| 2d4113e581 |
73
src/comment-routing.test.ts
Normal file
73
src/comment-routing.test.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import {
|
||||||
|
CLOSED_ISSUE_STATUSES,
|
||||||
|
nativeWakeCoversComment,
|
||||||
|
} from "./comment-routing.ts";
|
||||||
|
|
||||||
|
const CEO = "cdbfa8bc-3d61-41a4-a2e7-677ec7d34562";
|
||||||
|
const ANALYST = "752cebdd-6748-4a04-aacd-c7ab0294ef33";
|
||||||
|
|
||||||
|
// ── #16 AC: issue פתוח משויך-CEO, בלי reopened → הנייטיבי מכסה, אין invoke ──
|
||||||
|
test("open CEO-owned issue is covered natively (the #772 / CMPA-232 case)", () => {
|
||||||
|
for (const status of ["in_progress", "in_review", "todo", "blocked"]) {
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({ status, assigneeAgentId: CEO }),
|
||||||
|
true,
|
||||||
|
status,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// הכלל הוא "משויך לסוכן", לא "משויך ל-CEO": Paperclip מעיר כל assignee-סוכן.
|
||||||
|
test("open issue owned by any agent is covered natively", () => {
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({
|
||||||
|
status: "in_progress",
|
||||||
|
assigneeAgentId: ANALYST,
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── #16 AC: משויך לאדם / לא משויך → הנייטיבי מת → חובה לנתב ──
|
||||||
|
test("human-owned or unassigned open issue is NOT covered → plugin must route", () => {
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({ status: "in_review", assigneeAgentId: null }),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({
|
||||||
|
status: "in_review",
|
||||||
|
assigneeAgentId: undefined,
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({ status: "in_review", assigneeAgentId: "" }),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── סגור → Paperclip מדלג על ה-wakeup גם כשיש assignee-סוכן ──
|
||||||
|
test("closed issue is never covered natively, whoever owns it", () => {
|
||||||
|
for (const status of CLOSED_ISSUE_STATUSES) {
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({ status, assigneeAgentId: CEO }),
|
||||||
|
false,
|
||||||
|
status,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
nativeWakeCoversComment({ status, assigneeAgentId: null }),
|
||||||
|
false,
|
||||||
|
status,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// מראה של legal-ai `CLOSED_ISSUE_STATUSES` — שינוי שם מחייב שינוי כאן.
|
||||||
|
test("closed statuses mirror legal-ai needs_ceo_run()", () => {
|
||||||
|
assert.deepEqual([...CLOSED_ISSUE_STATUSES].sort(), ["cancelled", "done"]);
|
||||||
|
});
|
||||||
43
src/comment-routing.ts
Normal file
43
src/comment-routing.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* מסלול-יקיצה יחיד להערת-יו"ר (plugin-legal-ai #16, legal-ai #772).
|
||||||
|
*
|
||||||
|
* Paperclip מעיר **בעצמו** את הסוכן המשויך ל-issue על כל הערת-משתמש
|
||||||
|
* (`@paperclipai/server` routes/issues.js — `addWakeup(assigneeId, {reason:
|
||||||
|
* "issue_commented", payload.mutation: "comment"})`), ובלבד ש-(א) יש assignee-סוכן,
|
||||||
|
* (ב) ה-issue אינו סגור (`done`/`cancelled`), (ג) ההערה אינה של אותו סוכן עצמו.
|
||||||
|
* `ctx.agents.invoke` של הפלאגין על אותה הערה = ריצת-CEO שנייה במקביל: עבודה
|
||||||
|
* כפולה, שתי רשומות `chair_feedback`, שני issues לכותב (legal-ai #772; שוב
|
||||||
|
* 2026-11-01 על CMPA-232 — 3 ריצות כפולות, ~9$).
|
||||||
|
*
|
||||||
|
* ⚠️ מקור-האמת לכלל הוא **`needs_ceo_run()` ב-legal-ai `web/paperclip_client.py`**
|
||||||
|
* (נמדד על 120 יום ב-DB החי: agent-owned + open → 70/70 הערות קיבלו wakeup נייטיבי;
|
||||||
|
* human-owned/unassigned → ה-wakeup מכוון לאדם ומבוטל; closed → אין wakeup כלל).
|
||||||
|
* הפונקציה כאן היא **מראה** של אותו כלל בצד הפלאגין — אין דרך לקרוא ל-legal-ai
|
||||||
|
* מתוך event-handler בלי להוסיף תלות-רשת לנתיב-המסירה. **כל שינוי שם מחייב
|
||||||
|
* שינוי כאן**, ולהיפך (G2 — מסלול-החלטה אחד, שני מימושים שחייבים להישאר זהים).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** סטטוסים סופיים — Paperclip מדלג על ה-wakeup הנייטיבי בהם (`isClosed`). */
|
||||||
|
export const CLOSED_ISSUE_STATUSES: ReadonlySet<string> = new Set([
|
||||||
|
"done",
|
||||||
|
"cancelled",
|
||||||
|
]);
|
||||||
|
|
||||||
|
export interface RoutableIssue {
|
||||||
|
status: string;
|
||||||
|
assigneeAgentId?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* האם המסירה הנייטיבית של Paperclip כבר מעירה סוכן על הערה ב-issue הזה?
|
||||||
|
*
|
||||||
|
* `true` → **אין** להפעיל `ctx.agents.invoke` (זה יהיה המסלול הכפול).
|
||||||
|
* `false` → המסלול הנייטיבי מת (issue סגור, או משויך לאדם / לא משויך) — זו
|
||||||
|
* בדיוק הסיבה שמסלול-הפלאגין קיים (#164/#454), ויש לנתב ל-CEO.
|
||||||
|
*
|
||||||
|
* זהה ל-`not needs_ceo_run(issue)` ב-legal-ai.
|
||||||
|
*/
|
||||||
|
export function nativeWakeCoversComment(issue: RoutableIssue): boolean {
|
||||||
|
if (CLOSED_ISSUE_STATUSES.has(issue.status)) return false;
|
||||||
|
return Boolean(issue.assigneeAgentId);
|
||||||
|
}
|
||||||
@@ -194,6 +194,7 @@ export class LegalApi {
|
|||||||
export interface CaseStatusEntry {
|
export interface CaseStatusEntry {
|
||||||
case_number: string;
|
case_number: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
updated_at?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CaseSummary {
|
export interface CaseSummary {
|
||||||
|
|||||||
@@ -179,19 +179,13 @@ export default {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
jobs: [
|
jobs: [
|
||||||
{
|
// הושבת (legal-ai #1117, INV-INT9 — כותב יחיד ל-issue.status): הסנכרון עבר
|
||||||
jobKey: "sync-case-status",
|
// לצד-השרת (`_case_status_sync_loop` ב-legal-ai, CASE_STATUS_SYNC_MODE).
|
||||||
displayName: "Sync Legal Case Status",
|
// הסרה מההצהרה גורמת ל-Paperclip להעביר את הג'וב ל-`paused` בהתקנה הבאה.
|
||||||
description:
|
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
|
||||||
"Polls legal-ai for case status changes and updates Paperclip issues",
|
// הושבת (legal-ai #1117, הוראת חיים): תיק ללא תנועה לעיתים הוא מכוון, והתזכורות
|
||||||
schedule: "*/15 * * * *",
|
// היו רעש בלבד. הסרה מההצהרה => Paperclip מעביר ל-`paused` בהתקנה הבאה.
|
||||||
},
|
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
|
||||||
{
|
|
||||||
jobKey: "stale-case-reminder",
|
|
||||||
displayName: "תזכורת תיקים תקועים",
|
|
||||||
description: "מזהה תיקים שלא עודכנו 30+ ימים ומוסיף תגובה ל-issue",
|
|
||||||
schedule: "0 8 * * *",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
jobKey: "weekly-feedback-analysis",
|
jobKey: "weekly-feedback-analysis",
|
||||||
displayName: "ניתוח פידבק שבועי",
|
displayName: "ניתוח פידבק שבועי",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type {
|
|||||||
PluginWebhookInput,
|
PluginWebhookInput,
|
||||||
} from "@paperclipai/plugin-sdk";
|
} from "@paperclipai/plugin-sdk";
|
||||||
import { definePlugin, runWorker } from "@paperclipai/plugin-sdk";
|
import { definePlugin, runWorker } from "@paperclipai/plugin-sdk";
|
||||||
|
import { nativeWakeCoversComment } from "./comment-routing.js";
|
||||||
import {
|
import {
|
||||||
CompanyScopeUnavailableError,
|
CompanyScopeUnavailableError,
|
||||||
isCompanyScopeDenied,
|
isCompanyScopeDenied,
|
||||||
@@ -859,17 +860,21 @@ const plugin = definePlugin({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dedup against the host's native reopen-on-comment wake: when a comment
|
// מסלול-יקיצה יחיד (#16, legal-ai #772): Paperclip מעיר בעצמו את הסוכן
|
||||||
// reopens a `done` issue, the host already wakes that issue's assignee.
|
// המשויך על כל הערת-משתמש ב-issue פתוח — לא רק כשההערה פותחת-מחדש issue
|
||||||
// If the assignee IS this company's CEO, that native wake covers us —
|
// סגור (זה היה הכלל הקודם, `reopened === true`, והוא פספס את המקרה הנפוץ:
|
||||||
// invoking again would double-run the CEO. Skip ONLY in that exact case.
|
// issue פתוח ב-`in_review` משויך-CEO → שתי ריצות-CEO במקביל על אותה הערה).
|
||||||
// For issues owned by any other agent (e.g. an analyst sub-task), the
|
// הכלל נגזר מ-`needs_ceo_run()` ב-legal-ai — ראה comment-routing.ts.
|
||||||
// native wake targets the wrong agent (and the queued run is cancelled
|
// הפלאגין מנתב רק במקום שבו הנייטיבי מת: issue סגור, או משויך לאדם / לא משויך.
|
||||||
// with `issue_assignee_changed`), so we MUST route the comment to the CEO.
|
if (nativeWakeCoversComment(issue)) {
|
||||||
if (issue.assigneeAgentId === ceoAgentId && payload?.reopened === true) {
|
|
||||||
ctx.logger.info(
|
ctx.logger.info(
|
||||||
"Comment reopened CEO-owned issue; native wake handles it, skipping plugin route",
|
"Comment on open agent-owned issue; native wake handles it, skipping plugin route (#16)",
|
||||||
{ issueId, ceoAgentId },
|
{
|
||||||
|
issueId,
|
||||||
|
status: issue.status,
|
||||||
|
assigneeAgentId: issue.assigneeAgentId,
|
||||||
|
reopened: payload?.reopened === true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
// The comment IS being handled (natively) — stamp the marker so the
|
// The comment IS being handled (natively) — stamp the marker so the
|
||||||
// reconciliation sweep does not re-route it a second time.
|
// reconciliation sweep does not re-route it a second time.
|
||||||
@@ -1238,27 +1243,17 @@ const plugin = definePlugin({
|
|||||||
// double-routed. Runs every 2 minutes (manifest schedule).
|
// double-routed. Runs every 2 minutes (manifest schedule).
|
||||||
ctx.jobs.register("route-pending-comments", async (_job) => {
|
ctx.jobs.register("route-pending-comments", async (_job) => {
|
||||||
await runJobHandler("route-pending-comments", ctx.logger, async () => {
|
await runJobHandler("route-pending-comments", ctx.logger, async () => {
|
||||||
// כשל-מהיר: דחיית-scope (legal-ai issue #637) אינה "שגיאה
|
// רשימת החברות נלקחת ממפת ה-CEO ולא מ-`ctx.companies.list()` (legal-ai
|
||||||
// פר-issue" שאפשר להתעלם ממנה — היא אומרת שה-run **כולו** לא
|
// #1280): הקריאה הזו דורשת scope של instance, וה-host דוחה אותה
|
||||||
// יכול לעבוד. לזרוק מיד במקום לבלוע ולהמשיך ללולאה על 2
|
// באקראי בג'וב מתוזמן (invalidInvocationScope, ~21% מהריצות מ-10.11).
|
||||||
// חברות × 200 issues שכולן ייכשלו זהה. שגיאה אחרת (ולא scope)
|
// הלולאה ממילא מדלגת על חברה בלי CEO ממופה, ולכן הרשימה זהה
|
||||||
// נשארת warn+continue — זו העמידות האמיתית פר-issue.
|
// (אותו דפוס כמו `knownCompanyIds` ב-`resolveApiBase`).
|
||||||
let companies: Awaited<ReturnType<typeof ctx.companies.list>>;
|
//
|
||||||
try {
|
// כשל-מהיר נשאר ב-`issues.list`: דחיית-scope (legal-ai issue #637)
|
||||||
companies = await ctx.companies.list();
|
// אינה "שגיאה פר-issue" שאפשר להתעלם ממנה — היא אומרת שה-run
|
||||||
} catch (err) {
|
// **כולו** לא יכול לעבוד. שגיאה אחרת (ולא scope) נשארת
|
||||||
if (isCompanyScopeDenied(err)) {
|
// warn+continue — זו העמידות האמיתית פר-issue.
|
||||||
throw new CompanyScopeUnavailableError(
|
const companies = Object.keys(CEO_AGENT_IDS).map((id) => ({ id }));
|
||||||
"route-pending-comments",
|
|
||||||
"companies.list",
|
|
||||||
{ cause: err },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ctx.logger.warn("route-pending-comments: companies.list failed", {
|
|
||||||
error: String(err),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const company of companies) {
|
for (const company of companies) {
|
||||||
const ceoAgentId = CEO_AGENT_IDS[company.id];
|
const ceoAgentId = CEO_AGENT_IDS[company.id];
|
||||||
@@ -1391,7 +1386,7 @@ const plugin = definePlugin({
|
|||||||
if (!caseNumber) return null;
|
if (!caseNumber) return null;
|
||||||
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
|
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
|
||||||
try {
|
try {
|
||||||
const resp = await ctx.http.fetch(
|
const resp = await fetchLegalApi(
|
||||||
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/legal-arguments`,
|
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/legal-arguments`,
|
||||||
);
|
);
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
@@ -1428,7 +1423,7 @@ const plugin = definePlugin({
|
|||||||
if (!caseNumber) return [];
|
if (!caseNumber) return [];
|
||||||
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
|
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
|
||||||
try {
|
try {
|
||||||
const resp = await ctx.http.fetch(
|
const resp = await fetchLegalApi(
|
||||||
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/precedents`,
|
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/precedents`,
|
||||||
);
|
);
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
@@ -1467,7 +1462,7 @@ const plugin = definePlugin({
|
|||||||
const url = new URL(`${apiBase}/api/missing-precedents`);
|
const url = new URL(`${apiBase}/api/missing-precedents`);
|
||||||
url.searchParams.set("case_number", caseNumber);
|
url.searchParams.set("case_number", caseNumber);
|
||||||
url.searchParams.set("status", "open");
|
url.searchParams.set("status", "open");
|
||||||
const resp = await ctx.http.fetch(url.toString());
|
const resp = await fetchLegalApi(url.toString());
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
ctx.logger.warn("legal-case-missing-precedents: API error", {
|
ctx.logger.warn("legal-case-missing-precedents: API error", {
|
||||||
caseNumber,
|
caseNumber,
|
||||||
@@ -1488,13 +1483,13 @@ const plugin = definePlugin({
|
|||||||
|
|
||||||
ctx.data.register("legal-dashboard-stats", async () => {
|
ctx.data.register("legal-dashboard-stats", async () => {
|
||||||
try {
|
try {
|
||||||
const cases = await api.listCases();
|
const cases = await api.listCaseStatuses();
|
||||||
const byStatus: Record<string, number> = {};
|
const byStatus: Record<string, number> = {};
|
||||||
let weekActivity = 0;
|
let weekActivity = 0;
|
||||||
const weekAgoMs = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
const weekAgoMs = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
||||||
for (const c of cases) {
|
for (const c of cases) {
|
||||||
byStatus[c.status] = (byStatus[c.status] ?? 0) + 1;
|
byStatus[c.status] = (byStatus[c.status] ?? 0) + 1;
|
||||||
const updated = (c as { updated_at?: string | null }).updated_at;
|
const updated = c.updated_at;
|
||||||
if (updated) {
|
if (updated) {
|
||||||
const t = Date.parse(updated);
|
const t = Date.parse(updated);
|
||||||
if (!Number.isNaN(t) && t >= weekAgoMs) weekActivity += 1;
|
if (!Number.isNaN(t) && t >= weekAgoMs) weekActivity += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user