Compare commits
5 Commits
2a6165ac86
...
fix/1117-j
| Author | SHA1 | Date | |
|---|---|---|---|
| e324240b7e | |||
| 68f85717de | |||
| 50b29d4b12 | |||
| f3b972119b | |||
| c79a7a0b9f |
@@ -9,7 +9,7 @@
|
|||||||
* הלוגיקה כאן טהורה (תלויות מוזרקות) כדי שאפשר לבדוק אותה בלי host.
|
* הלוגיקה כאן טהורה (תלויות מוזרקות) כדי שאפשר לבדוק אותה בלי host.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** חברה → agent id של שטן-מליץ (Gemini) באותה חברה. */
|
/** חברה → agent id של שטן-מליץ באותה חברה (Fable מאז legal-ai #978; היה Gemini). */
|
||||||
export const DEVIL_AGENT_IDS: Record<string, string> = {
|
export const DEVIL_AGENT_IDS: Record<string, string> = {
|
||||||
"42a7acd0-30c5-4cbd-ac97-7424f65df294":
|
"42a7acd0-30c5-4cbd-ac97-7424f65df294":
|
||||||
"9c86e06a-5a92-4723-af6d-e8cc6ae1d45b", // CMP
|
"9c86e06a-5a92-4723-af6d-e8cc6ae1d45b", // CMP
|
||||||
@@ -17,6 +17,12 @@ export const DEVIL_AGENT_IDS: Record<string, string> = {
|
|||||||
"46cc1228-a232-410b-a36b-71a6928499a2", // CMPA
|
"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 DEFAULT_CASES_DIR = "/home/chaim/legal-ai/data/cases";
|
||||||
/** מזכר קצר מזה = כנראה ריצה ריקה/חלקית, לא סוגרים. */
|
/** מזכר קצר מזה = כנראה ריצה ריקה/חלקית, לא סוגרים. */
|
||||||
export const MIN_CRITIQUE_BYTES = 2000;
|
export const MIN_CRITIQUE_BYTES = 2000;
|
||||||
@@ -72,7 +78,7 @@ export type CloseOutcome =
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* מופעל על `agent.run.finished` (status=succeeded בלבד). סוגר את ה-issue רק אם:
|
* מופעל על `agent.run.finished` (status=succeeded בלבד). סוגר את ה-issue רק אם:
|
||||||
* הריצה של שטן-מליץ של אותה חברה, ה-issue שלו פתוח, וקיים `critique-gemini.md` עדכני ולא ריק.
|
* הריצה של שטן-מליץ של אותה חברה, ה-issue שלו פתוח, וקיים מזכר (`critique.md`) עדכני ולא ריק.
|
||||||
*/
|
*/
|
||||||
export async function closeDevilIssueIfDone(
|
export async function closeDevilIssueIfDone(
|
||||||
companyId: string | undefined,
|
companyId: string | undefined,
|
||||||
@@ -113,7 +119,7 @@ export async function closeDevilIssueIfDone(
|
|||||||
if (!st || st.size < MIN_CRITIQUE_BYTES || st.mtimeMs < created) {
|
if (!st || st.size < MIN_CRITIQUE_BYTES || st.mtimeMs < created) {
|
||||||
deps.log(
|
deps.log(
|
||||||
"warn",
|
"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,
|
issueId: issue.id,
|
||||||
caseNumber,
|
caseNumber,
|
||||||
|
|||||||
@@ -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,11 @@ export class LegalApi {
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
|
|
||||||
|
export interface CaseStatusEntry {
|
||||||
|
case_number: string;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CaseSummary {
|
export interface CaseSummary {
|
||||||
case_number: string;
|
case_number: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
24
src/worker-fetch.test.ts
Normal file
24
src/worker-fetch.test.ts
Normal 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
16
src/worker-fetch.ts
Normal 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);
|
||||||
|
}
|
||||||
@@ -13,7 +13,11 @@ import {
|
|||||||
resolveApiBaseFrom,
|
resolveApiBaseFrom,
|
||||||
runJobHandler,
|
runJobHandler,
|
||||||
} from "./company-scope.js";
|
} 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 type { StatusModelEntry } from "./legal-api.js";
|
||||||
import { LegalApi } from "./legal-api.js";
|
import { LegalApi } from "./legal-api.js";
|
||||||
import {
|
import {
|
||||||
@@ -31,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;
|
||||||
@@ -768,19 +773,26 @@ const plugin = definePlugin({
|
|||||||
: null;
|
: null;
|
||||||
},
|
},
|
||||||
statCritique: async (caseNumber) => {
|
statCritique: async (caseNumber) => {
|
||||||
try {
|
// critique.md = שטן מליץ על Fable (legal-ai #978); critique-gemini.md = תיקים ישנים.
|
||||||
const st = await stat(
|
for (const name of CRITIQUE_FILENAMES) {
|
||||||
`${casesDir}/${caseNumber}/documents/research/critique-gemini.md`,
|
try {
|
||||||
);
|
const st = await stat(
|
||||||
return { size: st.size, mtimeMs: st.mtimeMs };
|
`${casesDir}/${caseNumber}/documents/research/${name}`,
|
||||||
} catch (err) {
|
);
|
||||||
if ((err as NodeJS.ErrnoException).code === "ENOENT")
|
return { size: st.size, mtimeMs: st.mtimeMs };
|
||||||
return null;
|
} catch (err) {
|
||||||
throw err;
|
if ((err as NodeJS.ErrnoException).code !== "ENOENT")
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
// סטטוס בלבד, בלי comment: comment מעיר את ה-CEO פעם שנייה (user_commented).
|
// סטטוס בלבד, בלי comment: comment מעיר את ה-CEO פעם שנייה (user_commented).
|
||||||
closeIssue: async (id, companyId) => {
|
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);
|
await ctx.issues.update(id, { status: "done" }, companyId);
|
||||||
},
|
},
|
||||||
log: (level, msg, meta) => ctx.logger[level](msg, meta),
|
log: (level, msg, meta) => ctx.logger[level](msg, meta),
|
||||||
@@ -961,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 הזה נועד לתת.
|
||||||
@@ -1079,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)}`,
|
||||||
@@ -1158,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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user