6 Commits

Author SHA1 Message Date
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
5 changed files with 69 additions and 16 deletions

View File

@@ -36,6 +36,15 @@ export class LegalApi {
return this.request("/api/cases"); 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> { async getStatusModel(): Promise<StatusModel> {
return this.request("/api/status-model"); return this.request("/api/status-model");
} }
@@ -182,6 +191,12 @@ export class LegalApi {
// Types // Types
export interface CaseStatusEntry {
case_number: string;
status: string;
updated_at?: string | null;
}
export interface CaseSummary { export interface CaseSummary {
case_number: string; case_number: string;
title: string; title: string;

View File

@@ -179,13 +179,10 @@ 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",
schedule: "*/15 * * * *",
},
{ {
jobKey: "stale-case-reminder", jobKey: "stale-case-reminder",
displayName: "תזכורת תיקים תקועים", 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

@@ -35,6 +35,7 @@ import {
resolveStatusLabel, resolveStatusLabel,
type SyncCandidate, type SyncCandidate,
} from "./sync-target.js"; } from "./sync-target.js";
import { fetchLegalApi } from "./worker-fetch.js";
// Hoisted so onWebhook can access the context after setup() completes. // Hoisted so onWebhook can access the context after setup() completes.
let pluginCtx: PluginContext | null = null; let pluginCtx: PluginContext | null = null;
@@ -972,7 +973,7 @@ const plugin = definePlugin({
// כשה-scope נדחה (legal-ai issue #637). ה-`try/catch` הישן כאן בלע // כשה-scope נדחה (legal-ai issue #637). ה-`try/catch` הישן כאן בלע
// את הכשל, וה-run נרשם `succeeded` בלי לעשות כלום — 13,928 ריצות כוזבות. // את הכשל, וה-run נרשם `succeeded` בלי לעשות כלום — 13,928 ריצות כוזבות.
await runJobHandler("sync-case-status", ctx.logger, async () => { await runJobHandler("sync-case-status", ctx.logger, async () => {
const cases = await api.listCases(); const cases = await api.listCaseStatuses();
// נקבע מיד — לפני כל קריאת-מארח שעלולה ליפול. אחרת ריצה // נקבע מיד — לפני כל קריאת-מארח שעלולה ליפול. אחרת ריצה
// שנפלה באמצע (או `!companies.length`) הייתה מדווחת scanned=0 // שנפלה באמצע (או `!companies.length`) הייתה מדווחת scanned=0
// ומאבדת בדיוק את האבחנה שה-issue הזה נועד לתת. // ומאבדת בדיוק את האבחנה שה-issue הזה נועד לתת.
@@ -1090,9 +1091,9 @@ const plugin = definePlugin({
// כשל-fetch/API אמיתי חייב **לזרוק**, לא `return` בשקט — אחרת // כשל-fetch/API אמיתי חייב **לזרוק**, לא `return` בשקט — אחרת
// ה-run נרשם `succeeded` בלי שקרה כלום (legal-ai issue #637). // ה-run נרשם `succeeded` בלי שקרה כלום (legal-ai issue #637).
let resp: Awaited<ReturnType<typeof ctx.http.fetch>>; let resp: Response;
try { try {
resp = await ctx.http.fetch(`${apiBase}/api/cases/stale?days=30`); resp = await fetchLegalApi(`${apiBase}/api/cases/stale?days=30`);
} catch (err) { } catch (err) {
throw new Error( throw new Error(
`stale-case-reminder: fetch failed against ${apiBase}: ${String(err)}`, `stale-case-reminder: fetch failed against ${apiBase}: ${String(err)}`,
@@ -1169,7 +1170,7 @@ const plugin = definePlugin({
// throws CompanyScopeUnavailableError rather than guessing. // throws CompanyScopeUnavailableError rather than guessing.
const apiBase = await resolveApiBase(ctx); const apiBase = await resolveApiBase(ctx);
const resp = await ctx.http.fetch( const resp = await fetchLegalApi(
`${apiBase}/api/chair-feedback/weekly-summary`, `${apiBase}/api/chair-feedback/weekly-summary`,
); );
if (!resp.ok) { if (!resp.ok) {
@@ -1390,7 +1391,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) {
@@ -1427,7 +1428,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) {
@@ -1466,7 +1467,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,
@@ -1487,13 +1488,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;