16 Commits

Author SHA1 Message Date
976e8ebe2d Merge pull request 'fix(sweep): route-pending-comments לוקח חברות מ-CEO_AGENT_IDS ולא מ-companies.list (legal-ai#1280)' (#25) from fix/legal-ai-1280-sweep-company-ids into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 3s
2026-11-12 10:54:09 +00:00
c934a6be44 fix(sweep): route-pending-comments לוקח חברות מ-CEO_AGENT_IDS ולא מ-companies.list (legal-ai#1280)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 5s
ctx.companies.list() דורש scope של instance והמארח דוחה אותו באקראי בג'וב מתוזמן
(invalidInvocationScope, ~21% מהריצות מאז 10.11). הלולאה ממילא מדלגת על חברה בלי CEO
ממופה, ולכן הרשימה זהה. אותו דפוס כמו knownCompanyIds ב-resolveApiBase.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JVyJoEa3s1vA9XeNE6WyDu
2026-11-12 12:53:43 +02:00
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
c5a605ab1d chore: השבתת הג'וב sync-case-status — הסנכרון עבר ל-legal-ai (#1117)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 8s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 08:58:50 +02:00
517b3ee844 Merge pull request 'fix(ui): כלי הלשונית דרך fetch של ה-worker; דשבורד דרך status-index (legal-ai #1117)' (#21) from fix/1117-ui-handlers into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 5s
2026-10-24 17:27:54 +00:00
75aa931f85 fix(ui): כלי הלשונית (arguments/precedents/missing) דרך fetch של ה-worker; דשבורד דרך status-index (legal-ai #1117)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 6s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 20:24:03 +03:00
2d4113e581 Merge pull request 'fix(jobs): stale/weekly דרך fetch של ה-worker; sync-case-status דרך status-index (legal-ai #1117)' (#20) from fix/1117-job-fetch into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 4s
2026-10-24 16:09:23 +00:00
e324240b7e fix(jobs): stale/weekly דרך fetch של ה-worker, ו-sync-case-status דרך status-index (legal-ai #1117)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 8s
ctx.http.fetch נחסם ע"י הגנת-SSRF של Paperclip כלפי 127.0.0.1:8001 (stale-case-reminder,
weekly-feedback-analysis); sync-case-status קיבל 401 על GET /api/cases (session-only) ועובר
לנתיב המינימלי /api/cases/status-index שנוסף ל-legal-ai (PR #1118).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 19:06:26 +03:00
68f85717de Merge pull request 'feat(devil-closer): זיהוי critique.md של שטן מליץ על Fable' (#19) from feat/devil-critique-md into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 4s
2026-10-15 12:25:15 +00:00
50b29d4b12 feat(devil-closer): זיהוי critique.md של שטן מליץ על Fable (legal-ai #978)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 3s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRePqBSqn3kjwjg9puEJZz
2026-10-15 15:24:42 +03:00
f3b972119b Merge pull request 'fix(plugin): noqa מנומק ל-INT9 עבור סגירת issue שטן-מליץ' (#18) from fix/int9-noqa-devil-close into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 4s
2026-10-14 15:59:41 +00:00
c79a7a0b9f fix(plugin): noqa מנומק ל-INT9 עבור סגירת issue שטן-מליץ (תיקון CI אחרי #17)
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 3s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRePqBSqn3kjwjg9puEJZz
2026-10-14 18:59:28 +03:00
8 changed files with 244 additions and 66 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

@@ -9,7 +9,7 @@
* הלוגיקה כאן טהורה (תלויות מוזרקות) כדי שאפשר לבדוק אותה בלי host.
*/
/** חברה → agent id של שטן-מליץ (Gemini) באותה חברה. */
/** חברה → agent id של שטן-מליץ באותה חברה (Fable מאז legal-ai #978; היה Gemini). */
export const DEVIL_AGENT_IDS: Record<string, string> = {
"42a7acd0-30c5-4cbd-ac97-7424f65df294":
"9c86e06a-5a92-4723-af6d-e8cc6ae1d45b", // CMP
@@ -17,6 +17,12 @@ export const DEVIL_AGENT_IDS: Record<string, string> = {
"46cc1228-a232-410b-a36b-71a6928499a2", // CMPA
};
/** קובץ המזכר: critique.md (Fable, legal-ai #978); critique-gemini.md לתיקים שרצו לפני המעבר. */
export const CRITIQUE_FILENAMES = [
"critique.md",
"critique-gemini.md",
] as const;
export const DEFAULT_CASES_DIR = "/home/chaim/legal-ai/data/cases";
/** מזכר קצר מזה = כנראה ריצה ריקה/חלקית, לא סוגרים. */
export const MIN_CRITIQUE_BYTES = 2000;
@@ -72,7 +78,7 @@ export type CloseOutcome =
/**
* מופעל על `agent.run.finished` (status=succeeded בלבד). סוגר את ה-issue רק אם:
* הריצה של שטן-מליץ של אותה חברה, ה-issue שלו פתוח, וקיים `critique-gemini.md` עדכני ולא ריק.
* הריצה של שטן-מליץ של אותה חברה, ה-issue שלו פתוח, וקיים מזכר (`critique.md`) עדכני ולא ריק.
*/
export async function closeDevilIssueIfDone(
companyId: string | undefined,
@@ -113,7 +119,7 @@ export async function closeDevilIssueIfDone(
if (!st || st.size < MIN_CRITIQUE_BYTES || st.mtimeMs < created) {
deps.log(
"warn",
"devil auto-close: no fresh critique-gemini.md; leaving issue open",
"devil auto-close: no fresh critique memo; leaving issue open",
{
issueId: issue.id,
caseNumber,

View File

@@ -36,6 +36,15 @@ export class LegalApi {
return this.request("/api/cases");
}
/**
* Minimal `{case_number, status}` index for `sync-case-status` (legal-ai #1117).
* Lives on the internal machine route; the fuller `/api/cases` listing does not
* (session-only), so the sync job must not call `listCases()`.
*/
async listCaseStatuses(): Promise<CaseStatusEntry[]> {
return this.request("/api/cases/status-index");
}
async getStatusModel(): Promise<StatusModel> {
return this.request("/api/status-model");
}
@@ -182,6 +191,12 @@ export class LegalApi {
// Types
export interface CaseStatusEntry {
case_number: string;
status: string;
updated_at?: string | null;
}
export interface CaseSummary {
case_number: string;
title: string;

View File

@@ -179,19 +179,13 @@ export default {
},
],
jobs: [
{
jobKey: "sync-case-status",
displayName: "Sync Legal Case Status",
description:
"Polls legal-ai for case status changes and updates Paperclip issues",
schedule: "*/15 * * * *",
},
{
jobKey: "stale-case-reminder",
displayName: "תזכורת תיקים תקועים",
description: "מזהה תיקים שלא עודכנו 30+ ימים ומוסיף תגובה ל-issue",
schedule: "0 8 * * *",
},
// הושבת (legal-ai #1117, INV-INT9 — כותב יחיד ל-issue.status): הסנכרון עבר
// לצד-השרת (`_case_status_sync_loop` ב-legal-ai, CASE_STATUS_SYNC_MODE).
// הסרה מההצהרה גורמת ל-Paperclip להעביר את הג'וב ל-`paused` בהתקנה הבאה.
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
// הושבת (legal-ai #1117, הוראת חיים): תיק ללא תנועה לעיתים הוא מכוון, והתזכורות
// היו רעש בלבד. הסרה מההצהרה => Paperclip מעביר ל-`paused` בהתקנה הבאה.
// ה-handler ב-worker.ts נשאר רשום אך לא יופעל.
{
jobKey: "weekly-feedback-analysis",
displayName: "ניתוח פידבק שבועי",

24
src/worker-fetch.test.ts Normal file
View File

@@ -0,0 +1,24 @@
/// <reference types="node" />
import assert from "node:assert/strict";
import { test } from "node:test";
// Excluded from tsc (tsconfig.json), run natively via `node --test` (literal `.ts`).
import { fetchLegalApi } from "./worker-fetch.ts";
test("fetchLegalApi uses the worker's global fetch (not the host-mediated ctx.http.fetch)", async () => {
const original = globalThis.fetch;
let called = "";
globalThis.fetch = (async (url: string) => {
called = url;
return new Response("{}", { status: 200 });
}) as typeof fetch;
try {
const resp = await fetchLegalApi(
"http://127.0.0.1:8001/api/cases/stale?days=30",
);
assert.equal(resp.ok, true);
assert.equal(called, "http://127.0.0.1:8001/api/cases/stale?days=30");
} finally {
globalThis.fetch = original;
}
});

16
src/worker-fetch.ts Normal file
View File

@@ -0,0 +1,16 @@
/**
* `fetch` of the worker process — used by the scheduled jobs that read legal-ai's
* internal-machine routes at `http://127.0.0.1:8001`. `ctx.http.fetch` is host-mediated
* and Paperclip's SSRF guard rejects loopback/private targets ("All resolved IPs for
* 127.0.0.1 are in private/reserved ranges"), which is why `stale-case-reminder` and
* `weekly-feedback-analysis` failed (legal-ai #1117). `LegalApi` already uses this fetch.
*
* Kept in its own module (no TypeScript parameter properties) so `node --test` can
* load it in strip-only mode.
*/
export function fetchLegalApi(
url: string,
init?: RequestInit,
): Promise<Response> {
return fetch(url, init);
}

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,
@@ -13,7 +14,11 @@ import {
resolveApiBaseFrom,
runJobHandler,
} from "./company-scope.js";
import { closeDevilIssueIfDone, DEFAULT_CASES_DIR } from "./devil-closer.js";
import {
CRITIQUE_FILENAMES,
closeDevilIssueIfDone,
DEFAULT_CASES_DIR,
} from "./devil-closer.js";
import type { StatusModelEntry } from "./legal-api.js";
import { LegalApi } from "./legal-api.js";
import {
@@ -31,6 +36,7 @@ import {
resolveStatusLabel,
type SyncCandidate,
} from "./sync-target.js";
import { fetchLegalApi } from "./worker-fetch.js";
// Hoisted so onWebhook can access the context after setup() completes.
let pluginCtx: PluginContext | null = null;
@@ -768,19 +774,26 @@ const plugin = definePlugin({
: null;
},
statCritique: async (caseNumber) => {
// critique.md = שטן מליץ על Fable (legal-ai #978); critique-gemini.md = תיקים ישנים.
for (const name of CRITIQUE_FILENAMES) {
try {
const st = await stat(
`${casesDir}/${caseNumber}/documents/research/critique-gemini.md`,
`${casesDir}/${caseNumber}/documents/research/${name}`,
);
return { size: st.size, mtimeMs: st.mtimeMs };
} catch (err) {
if ((err as NodeJS.ErrnoException).code === "ENOENT")
return null;
if ((err as NodeJS.ErrnoException).code !== "ENOENT")
throw err;
}
}
return null;
},
// סטטוס בלבד, בלי comment: comment מעיר את ה-CEO פעם שנייה (user_commented).
closeIssue: async (id, companyId) => {
// כותב-סטטוס שני וצר בכוונה: רק issue של שטן-מליץ (נבדק בכותרת ובסוכן), רק open→done,
// רק אחרי ריצה מוצלחת + מזכר (critique.md) עדכני (devil-closer.ts). בלי זה הסוכן
// (בלי shell, #872) לא סוגר והתהליך נתקע; אין flip-flop כי done סופי.
// noqa: INT9 — סגירת issue של שטן-מליץ אחרי ריצה מוצלחת (legal-ai #892), ראה devil-closer.ts
await ctx.issues.update(id, { status: "done" }, companyId);
},
log: (level, msg, meta) => ctx.logger[level](msg, meta),
@@ -847,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.
@@ -961,7 +978,7 @@ const plugin = definePlugin({
// כשה-scope נדחה (legal-ai issue #637). ה-`try/catch` הישן כאן בלע
// את הכשל, וה-run נרשם `succeeded` בלי לעשות כלום — 13,928 ריצות כוזבות.
await runJobHandler("sync-case-status", ctx.logger, async () => {
const cases = await api.listCases();
const cases = await api.listCaseStatuses();
// נקבע מיד — לפני כל קריאת-מארח שעלולה ליפול. אחרת ריצה
// שנפלה באמצע (או `!companies.length`) הייתה מדווחת scanned=0
// ומאבדת בדיוק את האבחנה שה-issue הזה נועד לתת.
@@ -1079,9 +1096,9 @@ const plugin = definePlugin({
// כשל-fetch/API אמיתי חייב **לזרוק**, לא `return` בשקט — אחרת
// ה-run נרשם `succeeded` בלי שקרה כלום (legal-ai issue #637).
let resp: Awaited<ReturnType<typeof ctx.http.fetch>>;
let resp: Response;
try {
resp = await ctx.http.fetch(`${apiBase}/api/cases/stale?days=30`);
resp = await fetchLegalApi(`${apiBase}/api/cases/stale?days=30`);
} catch (err) {
throw new Error(
`stale-case-reminder: fetch failed against ${apiBase}: ${String(err)}`,
@@ -1158,7 +1175,7 @@ const plugin = definePlugin({
// throws CompanyScopeUnavailableError rather than guessing.
const apiBase = await resolveApiBase(ctx);
const resp = await ctx.http.fetch(
const resp = await fetchLegalApi(
`${apiBase}/api/chair-feedback/weekly-summary`,
);
if (!resp.ok) {
@@ -1226,27 +1243,17 @@ const plugin = definePlugin({
// double-routed. Runs every 2 minutes (manifest schedule).
ctx.jobs.register("route-pending-comments", async (_job) => {
await runJobHandler("route-pending-comments", ctx.logger, async () => {
// כשל-מהיר: דחיית-scope (legal-ai issue #637) אינה "שגיאה
// פר-issue" שאפשר להתעלם ממנה — היא אומרת שה-run **כולו** לא
// יכול לעבוד. לזרוק מיד במקום לבלוע ולהמשיך ללולאה על 2
// חברות × 200 issues שכולן ייכשלו זהה. שגיאה אחרת (ולא scope)
// נשארת warn+continue — זו העמידות האמיתית פר-issue.
let companies: Awaited<ReturnType<typeof ctx.companies.list>>;
try {
companies = await ctx.companies.list();
} catch (err) {
if (isCompanyScopeDenied(err)) {
throw new CompanyScopeUnavailableError(
"route-pending-comments",
"companies.list",
{ cause: err },
);
}
ctx.logger.warn("route-pending-comments: companies.list failed", {
error: String(err),
});
return;
}
// רשימת החברות נלקחת ממפת ה-CEO ולא מ-`ctx.companies.list()` (legal-ai
// #1280): הקריאה הזו דורשת scope של instance, וה-host דוחה אותה
// באקראי בג'וב מתוזמן (invalidInvocationScope, ~21% מהריצות מ-10.11).
// הלולאה ממילא מדלגת על חברה בלי CEO ממופה, ולכן הרשימה זהה
// (אותו דפוס כמו `knownCompanyIds` ב-`resolveApiBase`).
//
// כשל-מהיר נשאר ב-`issues.list`: דחיית-scope (legal-ai issue #637)
// אינה "שגיאה פר-issue" שאפשר להתעלם ממנה — היא אומרת שה-run
// **כולו** לא יכול לעבוד. שגיאה אחרת (ולא scope) נשארת
// warn+continue — זו העמידות האמיתית פר-issue.
const companies = Object.keys(CEO_AGENT_IDS).map((id) => ({ id }));
for (const company of companies) {
const ceoAgentId = CEO_AGENT_IDS[company.id];
@@ -1379,7 +1386,7 @@ const plugin = definePlugin({
if (!caseNumber) return null;
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
try {
const resp = await ctx.http.fetch(
const resp = await fetchLegalApi(
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/legal-arguments`,
);
if (!resp.ok) {
@@ -1416,7 +1423,7 @@ const plugin = definePlugin({
if (!caseNumber) return [];
const apiBase = await resolveApiBase(ctx, companyIdOf(params));
try {
const resp = await ctx.http.fetch(
const resp = await fetchLegalApi(
`${apiBase}/api/cases/${encodeURIComponent(caseNumber)}/precedents`,
);
if (!resp.ok) {
@@ -1455,7 +1462,7 @@ const plugin = definePlugin({
const url = new URL(`${apiBase}/api/missing-precedents`);
url.searchParams.set("case_number", caseNumber);
url.searchParams.set("status", "open");
const resp = await ctx.http.fetch(url.toString());
const resp = await fetchLegalApi(url.toString());
if (!resp.ok) {
ctx.logger.warn("legal-case-missing-precedents: API error", {
caseNumber,
@@ -1476,13 +1483,13 @@ const plugin = definePlugin({
ctx.data.register("legal-dashboard-stats", async () => {
try {
const cases = await api.listCases();
const cases = await api.listCaseStatuses();
const byStatus: Record<string, number> = {};
let weekActivity = 0;
const weekAgoMs = Date.now() - 7 * 24 * 60 * 60 * 1000;
for (const c of cases) {
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) {
const t = Date.parse(updated);
if (!Number.isNaN(t) && t >= weekAgoMs) weekActivity += 1;