5 Commits

Author SHA1 Message Date
f0925982c9 Merge pull request 'fix(routing): מסלול-יקיצה יחיד להערת-יו"ר — דילוג על invoke כשהנייטיבי מכסה (#16)' (#24) from fix/16-single-wake-path into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 4s
2026-11-01 15:55:18 +00:00
cfbeb582fa fix(routing): מסלול-יקיצה יחיד להערת-יו"ר — דילוג על invoke כשהנייטיבי מכסה (#16)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 4s
Paperclip מעיר בעצמו את הסוכן המשויך על כל הערת-משתמש ב-issue פתוח
(routes/issues.js: reason "issue_commented", mutation "comment"). הפלאגין דילג
על הניתוב רק כש-`reopened === true`, ולכן כל הוראת-יו"ר על issue פתוח
משויך-CEO הפעילה שתי ריצות-CEO במקביל (legal-ai #772; 2026-11-01 על CMPA-232:
3 ריצות כפולות, ~9$, רשומות chair_feedback כפולות).

הכלל עכשיו הוא מראה של `needs_ceo_run()` ב-legal-ai (comment-routing.ts):
issue פתוח + assignee-סוכן → הנייטיבי מכסה → אין invoke, יש marker.
סגור / משויך-אדם / לא-משויך → הנייטיבי מת → ניתוב כמו היום (#164/#454).

Closes #16

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-01 17:53:55 +02:00
4550c4132a Merge pull request 'chore: השבתת הג׳וב stale-case-reminder (legal-ai#1117)' (#23) from chore/1117-disable-stale-case-reminder into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 3s
2026-10-26 10:34:26 +00:00
294833ccc5 chore: השבתת הג'וב stale-case-reminder — רעש בלבד (#1117)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 4s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 12:34:24 +02:00
f48579d574 Merge pull request 'chore: השבתת הג׳וב sync-case-status — הסנכרון עבר ל-legal-ai (legal-ai#1117)' (#22) from chore/1117-disable-sync-case-status into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 4s
2026-10-26 06:58:53 +00:00
4 changed files with 134 additions and 16 deletions

View 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
View 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);
}

View File

@@ -183,12 +183,9 @@ export default {
// לצד-השרת (`_case_status_sync_loop` ב-legal-ai, CASE_STATUS_SYNC_MODE).
// הסרה מההצהרה גורמת ל-Paperclip להעביר את הג'וב ל-`paused` בהתקנה הבאה.
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
{
jobKey: "stale-case-reminder",
displayName: "תזכורת תיקים תקועים",
description: "מזהה תיקים שלא עודכנו 30+ ימים ומוסיף תגובה ל-issue",
schedule: "0 8 * * *",
},
// הושבת (legal-ai #1117, הוראת חיים): תיק ללא תנועה לעיתים הוא מכוון, והתזכורות
// היו רעש בלבד. הסרה מההצהרה => Paperclip מעביר ל-`paused` בהתקנה הבאה.
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
{
jobKey: "weekly-feedback-analysis",
displayName: "ניתוח פידבק שבועי",

View File

@@ -6,6 +6,7 @@ import type {
PluginWebhookInput,
} from "@paperclipai/plugin-sdk";
import { definePlugin, runWorker } from "@paperclipai/plugin-sdk";
import { nativeWakeCoversComment } from "./comment-routing.js";
import {
CompanyScopeUnavailableError,
isCompanyScopeDenied,
@@ -859,17 +860,21 @@ const plugin = definePlugin({
return;
}
// Dedup against the host's native reopen-on-comment wake: when a comment
// reopens a `done` issue, the host already wakes that issue's assignee.
// If the assignee IS this company's CEO, that native wake covers us —
// invoking again would double-run the CEO. Skip ONLY in that exact case.
// For issues owned by any other agent (e.g. an analyst sub-task), the
// native wake targets the wrong agent (and the queued run is cancelled
// with `issue_assignee_changed`), so we MUST route the comment to the CEO.
if (issue.assigneeAgentId === ceoAgentId && payload?.reopened === true) {
// מסלול-יקיצה יחיד (#16, legal-ai #772): Paperclip מעיר בעצמו את הסוכן
// המשויך על כל הערת-משתמש ב-issue פתוח — לא רק כשההערה פותחת-מחדש issue
// סגור (זה היה הכלל הקודם, `reopened === true`, והוא פספס את המקרה הנפוץ:
// issue פתוח ב-`in_review` משויך-CEO → שתי ריצות-CEO במקביל על אותה הערה).
// הכלל נגזר מ-`needs_ceo_run()` ב-legal-ai — ראה comment-routing.ts.
// הפלאגין מנתב רק במקום שבו הנייטיבי מת: issue סגור, או משויך לאדם / לא משויך.
if (nativeWakeCoversComment(issue)) {
ctx.logger.info(
"Comment reopened CEO-owned issue; native wake handles it, skipping plugin route",
{ issueId, ceoAgentId },
"Comment on open agent-owned issue; native wake handles it, skipping plugin route (#16)",
{
issueId,
status: issue.status,
assigneeAgentId: issue.assigneeAgentId,
reopened: payload?.reopened === true,
},
);
// The comment IS being handled (natively) — stamp the marker so the
// reconciliation sweep does not re-route it a second time.