11 Commits

Author SHA1 Message Date
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
2a6165ac86 Merge pull request 'feat(plugin): סגירה אוטומטית של issue שטן-מליץ אחרי ריצה מוצלחת (legal-ai #892)' (#17) from feat/devil-issue-autoclose into main
Some checks failed
INV-INT9 issue.status write-ownership / int9-guard (push) Failing after 3s
2026-10-14 15:58:47 +00:00
c51f8c36e7 feat(plugin): סגירה אוטומטית של issue שטן-מליץ אחרי ריצה מוצלחת — מעיר את ה-CEO (legal-ai #892)
Some checks failed
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Failing after 6s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRePqBSqn3kjwjg9puEJZz
2026-10-14 18:56:07 +03:00
5a5fdd9162 Merge pull request 'ci(int9): חיווט שער-INV-INT9 ל-Gitea Actions — 🚧 חסום עד שיירשם runner (legal-ai #618)' (#15) from chore/618-int9-workflow-enable into main
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (push) Successful in 3s
2026-09-02 11:29:38 +00:00
76db4aadb5 ci(int9): חיווט שער-INV-INT9 ל-Gitea Actions (legal-ai #618) — חסום עד שיירשם runner
All checks were successful
INV-INT9 issue.status write-ownership / int9-guard (pull_request) Successful in 3s
הסקריפט `scripts/int9-guard.mjs` כבר ב-`main` (PR #14) ורץ ידנית דרך
`npm run int9:guard`. הקובץ כאן הוא החיווט שלו ל-CI.

**אל תמזג לפני שיירשם runner ל-plugin-legal-ai.** ה-runner היחיד על nautilus
רשום בהיקף-repo ל-`legal-ai` בלבד (`action_runner.repo_id = 6`), ולכן job של
הריפו הזה לא נאסף לעולם — נמדד: ריצה 3200 / job 3250 ב-`queued` עם
`started_at: 1970-01-01`, בזמן שה-runner היה `busy: false` והריץ 7/7 שערים
של legal-ai. מיזוג עכשיו היה מייצר check תקוע-לנצח על **כל** PR עתידי בריפו.

ה-PR הזה הוא גם המדידה: ביום שיירשם runner הוא יהפוך לירוק מעצמו.

Refs ezer-mishpati/legal-ai#618

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 04:41:53 +03:00
c6c0b76914 Merge pull request 'chore(int9): שער-סטטי ל-INV-INT9 — issues.update({status}) רק במסלול sync-case-status (legal-ai #618)' (#14) from chore/618-inv-int9-ci-gate into main 2026-09-02 01:41:23 +00:00
b24d816cc0 chore(int9): שער-סטטי ל-INV-INT9 — issues.update({status}) רק במסלול sync-case-status (legal-ai #618)
ל-`issue.status` כותב לגיטימי אחד בפלאגין: הג'וב `sync-case-status`
(`ctx.jobs.register("sync-case-status", …)` ב-`src/worker.ts`). עד היום
האכיפה הייתה code-review בלבד — וזה בדיוק מה שאפשר את הבאג של legal-ai
‏#446 (flip-flop `done → in_progress`), כותב שני שנכנס בלי שאיש שם לב.

`scripts/int9-guard.mjs` — Node ESM חסר-תלויות. טוקנייזר תו-תו
(מחרוזות/תבניות עם `${}` מקונן/הערות/רגקס-ליטרלים) בונה מסכת "קוד רגיל",
ומעליה: כל `jobs.register("sync-case-status", …)` מגדיר **טווח-תווים מותר**
(איזון-סוגריים), וכל `issues.update(…)` שרשימת-הארגומנטים שלו מכילה את
המזהה `status` חייב לשבת בתוכו.

הגרעיניות היא טווח-קוד ולא רשימת-קבצים (הדפוס של `leak_guard.py` ב-legal-ai)
במכוון: הקריאה המותרת היחידה וכל קריאה עתידית אסורה יושבות באותו
`worker.ts`. הטווח נגזר מהמבנה האמיתי, ולכן שורד מעבר של הג'וב לקובץ אחר —
ושינוי שם-הג'וב מפיל את השער בקול במקום לפתוח חור שקט.

חריגה מכוונת: `// noqa: INT9 — <נימוק>`. `noqa: INT9` בלי נימוק הוא הפרה
בעצמו — אין השתקה שקטה. כשל-פענוח (סוגר שלא נסגר) מפיל את השער ולא נבלע.

`--self-test` מריץ 5 פיקסצ'רים (`scripts/fixtures/int9/`, מחוץ ל-`src/`
בכוונה) ומאמת ספירת-הפרות מדויקת — הוכחה שהשער נושך.

**ללא חיווט-CI.** ה-runner היחיד על nautilus רשום בהיקף-repo ל-`legal-ai`
בלבד (`action_runner.repo_id = 6`), ולכן job של הריפו הזה לא נאסף לעולם
(נמדד: ריצה 3200 / job 3250 תקוע ב-`queued`, `started_at: 1970-01-01`).
קובץ ה-workflow יושב ב-PR נפרד וחסום, כדי שלא ייכנס ל-`main` שער שמייצר
check תקוע-לנצח בכל PR עתידי. עד אז: `npm run int9:guard` /
`npm run int9:guard:self-test`.

מגבלה מוצהרת: תיל-מעידה סטטי, לא הוכחה — `issues.update(id, patch)` שבו
אובייקט-העדכון נבנה במקום אחר אינו נתפס.

Refs ezer-mishpati/legal-ai#618

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 04:40:19 +03:00
9 changed files with 427 additions and 5 deletions

View File

@@ -13,6 +13,14 @@ name: INV-INT9 issue.status write-ownership
# no reason is itself a violation — exceptions must be argued in writing).
#
# Pure Node, zero dependencies (scripts/int9-guard.mjs) — no `npm ci` needed.
#
# ⚠️ חסום למיזוג. אין היום runner ל-Gitea Actions בהיקף הריפו הזה: ה-runner
# היחיד על nautilus רשום בהיקף-repo ל-`legal-ai` בלבד (`action_runner.repo_id = 6`),
# ולכן job שנפתח כאן לא נאסף לעולם — נמדד ב-legal-ai #618: ריצה 3200 / job 3250
# ישבה ב-`queued` עם `started_at: 1970-01-01` בזמן שה-runner היה `busy: false`.
# ה-PR הזה נשאר פתוח **בכוונה** ומשמש כמדידה: ביום שיירשם runner לריפו הזה הוא
# יהפוך לירוק מעצמו, וזו תהיה הראיה ש-AC2 של #618 סופק. עד אז השער רץ ידנית:
# `npm run int9:guard` · `npm run int9:guard:self-test`.
on:
pull_request:

View File

@@ -14,7 +14,9 @@
"format": "biome format --write src/",
"format:check": "biome format src/",
"biome": "biome check src/",
"biome:fix": "biome check --write src/"
"biome:fix": "biome check --write src/",
"int9:guard": "node scripts/int9-guard.mjs",
"int9:guard:self-test": "node scripts/int9-guard.mjs --self-test"
},
"dependencies": {
"@paperclipai/plugin-sdk": "^2026.722.0",

View File

@@ -39,6 +39,18 @@
* node scripts/int9-guard.mjs <path>... # scan only the given files/directories
* node scripts/int9-guard.mjs --self-test # run the fixture suite (scripts/fixtures/int9/), prove the gate bites
*
* NOT WIRED INTO CI YET: the Gitea Actions runner on this server is
* registered at *repository* scope for `legal-ai` only
* (`action_runner.repo_id = 6`), so any job queued for `plugin-legal-ai` is
* never dispatched — measured on legal-ai issue #618, run 3200 / job 3250
* sat in `queued` with `started_at: 1970-01-01`. Until a runner is
* registered for this repo, run this by hand:
* npm run int9:guard
* npm run int9:guard:self-test
* The workflow file itself (`.gitea/workflows/int9-guard.yaml`) lives in a
* separate, deliberately-blocked PR, so merging it does not leave a
* permanently-pending check on every future PR in this repo.
*
* Zero dependencies (node:fs / node:path / node:process only) — no `npm ci`
* needed in CI; the runner image ships node 24.
*/

138
src/devil-closer.test.ts Normal file
View File

@@ -0,0 +1,138 @@
/// <reference types="node" />
import assert from "node:assert/strict";
import { test } from "node:test";
import {
type CloseDeps,
caseNumberFromTitle,
closeDevilIssueIfDone,
DEVIL_AGENT_IDS,
} from "./devil-closer.ts";
const CMPA = "8639e837-4c9d-47fa-a76b-95788d651896";
const DEVIL = DEVIL_AGENT_IDS[CMPA];
const TITLE = "[ערר 8165-11-25] שטן-מליץ — red-team על הניתוח";
function deps(over: Partial<CloseDeps> = {}) {
const closed: string[] = [];
const d: CloseDeps = {
getIssue: async (id) => ({
id,
title: TITLE,
status: "in_progress",
assigneeAgentId: DEVIL,
createdAt: "2026-10-14T12:45:58Z",
}),
statCritique: async () => ({
size: 39261,
mtimeMs: Date.parse("2026-10-14T13:29:50Z"),
}),
closeIssue: async (id) => {
closed.push(id);
},
log: () => {},
...over,
};
return { d, closed };
}
const RUN = { agentId: DEVIL, issueId: "i1", status: "succeeded" };
test("caseNumberFromTitle", () => {
assert.equal(caseNumberFromTitle(TITLE), "8165-11-25");
assert.equal(caseNumberFromTitle("[ערר 8027/25] x"), "8027/25");
assert.equal(caseNumberFromTitle("בלי מספר"), null);
});
test("סוגר כשהכול תקין", async () => {
const { d, closed } = deps();
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "closed");
assert.deepEqual(closed, ["i1"]);
});
test("לא סוכן שטן → לא נוגע", async () => {
const { d, closed } = deps();
assert.equal(
await closeDevilIssueIfDone(CMPA, { ...RUN, agentId: "other" }, d),
"not_devil_run",
);
assert.equal(closed.length, 0);
});
test("חברה לא מוכרת → לא נוגע", async () => {
const { d } = deps();
assert.equal(await closeDevilIssueIfDone("nope", RUN, d), "not_devil_run");
});
test("ריצה שלא הצליחה → לא סוגר", async () => {
const { d, closed } = deps();
assert.equal(
await closeDevilIssueIfDone(CMPA, { ...RUN, status: "failed" }, d),
"not_devil_run",
);
assert.equal(closed.length, 0);
});
test("issue שאינו של שטן (כותרת אחרת) → לא סוגר", async () => {
const { d, closed } = deps({
getIssue: async (id) => ({
id,
title: "[ערר 1-1-1] ניתוח משפטי",
status: "in_progress",
assigneeAgentId: DEVIL,
}),
});
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "not_devil_issue");
assert.equal(closed.length, 0);
});
test("כבר סגור → לא סוגר שוב", async () => {
const { d, closed } = deps({
getIssue: async (id) => ({
id,
title: TITLE,
status: "done",
assigneeAgentId: DEVIL,
}),
});
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "already_closed");
assert.equal(closed.length, 0);
});
test("אין קובץ מזכר → נשאר פתוח", async () => {
const { d, closed } = deps({ statCritique: async () => null });
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable");
assert.equal(closed.length, 0);
});
test("קובץ ישן מלפני יצירת ה-issue → נשאר פתוח", async () => {
const { d, closed } = deps({
statCritique: async () => ({
size: 39261,
mtimeMs: Date.parse("2026-10-01T00:00:00Z"),
}),
});
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable");
assert.equal(closed.length, 0);
});
test("קובץ קצר מדי → נשאר פתוח", async () => {
const { d, closed } = deps({
statCritique: async () => ({
size: 300,
mtimeMs: Date.parse("2026-10-14T13:29:50Z"),
}),
});
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable");
assert.equal(closed.length, 0);
});
test("כשל גישה לקובץ → נשאר פתוח (fail-safe)", async () => {
const { d, closed } = deps({
statCritique: async () => {
throw new Error("EACCES");
},
});
assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "stat_failed");
assert.equal(closed.length, 0);
});

142
src/devil-closer.ts Normal file
View File

@@ -0,0 +1,142 @@
/**
* סגירה אוטומטית של issue "שטן-מליץ" אחרי ריצה מוצלחת (legal-ai #892).
*
* הרקע: סוכן Gemini רץ בלי shell (#872) ולכן אינו יכול לסגור את ה-issue שלו.
* Paperclip מעיר את ה-CEO רק על `issue_children_completed` (ילד ב-`done`), ו-issue
* שנשאר פתוח עובר ל-`blocked` ("successful run missing disposition") — וה-CEO אינו
* מתעורר לעולם (אין לו heartbeat מחזורי). התוצאה בתיק 8165-11-25: המזכר נכתב והתהליך נתקע.
*
* הלוגיקה כאן טהורה (תלויות מוזרקות) כדי שאפשר לבדוק אותה בלי host.
*/
/** חברה → 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
"8639e837-4c9d-47fa-a76b-95788d651896":
"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;
const CLOSED = new Set(["done", "cancelled"]);
export interface DevilIssueLike {
id: string;
title: string;
status: string;
assigneeAgentId?: string | null;
createdAt?: string | Date | null;
}
export interface DevilRunPayload {
agentId?: string;
issueId?: string | null;
status?: string;
}
export interface CloseDeps {
getIssue(issueId: string, companyId: string): Promise<DevilIssueLike | null>;
/** גודל + זמן-שינוי של הקובץ, או null אם אינו קיים. זורק רק על כשל-גישה. */
statCritique(
caseNumber: string,
): Promise<{ size: number; mtimeMs: number } | null>;
closeIssue(issueId: string, companyId: string): Promise<void>;
log(
level: "info" | "warn",
msg: string,
meta?: Record<string, unknown>,
): void;
}
export function caseNumberFromTitle(title: string): string | null {
const m = title.match(/\[ערר\s+([^\]\s]+)\]/);
return m ? m[1] : null;
}
export function isDevilTitle(title: string): boolean {
return title.includes("שטן-מליץ");
}
export type CloseOutcome =
| "closed"
| "not_devil_run"
| "no_issue"
| "not_devil_issue"
| "already_closed"
| "no_case_number"
| "no_deliverable"
| "stat_failed";
/**
* מופעל על `agent.run.finished` (status=succeeded בלבד). סוגר את ה-issue רק אם:
* הריצה של שטן-מליץ של אותה חברה, ה-issue שלו פתוח, וקיים מזכר (`critique.md`) עדכני ולא ריק.
*/
export async function closeDevilIssueIfDone(
companyId: string | undefined,
payload: DevilRunPayload | null,
deps: CloseDeps,
): Promise<CloseOutcome> {
if (!companyId || !payload) return "not_devil_run";
const devilId = DEVIL_AGENT_IDS[companyId];
if (!devilId || payload.agentId !== devilId) return "not_devil_run";
if (payload.status && payload.status !== "succeeded") return "not_devil_run";
if (!payload.issueId) return "no_issue";
const issue = await deps.getIssue(payload.issueId, companyId);
if (!issue) return "no_issue";
if (issue.assigneeAgentId !== devilId || !isDevilTitle(issue.title)) {
return "not_devil_issue";
}
if (CLOSED.has(issue.status)) return "already_closed";
const caseNumber = caseNumberFromTitle(issue.title);
if (!caseNumber) return "no_case_number";
let st: { size: number; mtimeMs: number } | null;
try {
st = await deps.statCritique(caseNumber);
} catch {
deps.log(
"warn",
"devil auto-close: critique stat failed; leaving issue open",
{
issueId: issue.id,
caseNumber,
},
);
return "stat_failed";
}
const created = issue.createdAt ? new Date(issue.createdAt).getTime() : 0;
if (!st || st.size < MIN_CRITIQUE_BYTES || st.mtimeMs < created) {
deps.log(
"warn",
"devil auto-close: no fresh critique memo; leaving issue open",
{
issueId: issue.id,
caseNumber,
size: st?.size ?? null,
},
);
return "no_deliverable";
}
await deps.closeIssue(issue.id, companyId);
deps.log(
"info",
"devil auto-close: issue closed (CEO is woken by issue_children_completed)",
{
issueId: issue.id,
caseNumber,
},
);
return "closed";
}

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,11 @@ export class LegalApi {
// Types
export interface CaseStatusEntry {
case_number: string;
status: string;
}
export interface CaseSummary {
case_number: string;
title: string;

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

@@ -1,3 +1,6 @@
/// <reference types="node" />
import { stat } from "node:fs/promises";
import type {
PluginContext,
PluginWebhookInput,
@@ -10,6 +13,11 @@ import {
resolveApiBaseFrom,
runJobHandler,
} from "./company-scope.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 {
@@ -27,6 +35,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;
@@ -739,6 +748,63 @@ const plugin = definePlugin({
}
}
// ── שטן-מליץ: סגירה אוטומטית אחרי ריצה מוצלחת (legal-ai #892) ──
// הסוכן רץ בלי shell ולכן אינו יכול לסגור את ה-issue שלו; בלי `done` ה-CEO
// לעולם לא מתעורר (`issue_children_completed`). ראה devil-closer.ts.
ctx.events.on("agent.run.finished", async (event) => {
try {
const casesDir = process.env.LEGAL_AI_CASES_DIR || DEFAULT_CASES_DIR;
await closeDevilIssueIfDone(
event.companyId,
(event.payload ?? null) as Parameters<
typeof closeDevilIssueIfDone
>[1],
{
getIssue: async (id, companyId) => {
const i = await ctx.issues.get(id, companyId);
return i
? {
id: i.id,
title: i.title,
status: i.status,
assigneeAgentId: i.assigneeAgentId,
createdAt: i.createdAt,
}
: 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/${name}`,
);
return { size: st.size, mtimeMs: st.mtimeMs };
} catch (err) {
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),
},
);
} catch (err) {
ctx.logger.warn("devil auto-close handler failed", {
error: err instanceof Error ? err.name : "unknown",
});
}
});
ctx.events.on("issue.comment.created", async (event) => {
// Only intercept human comments — not agent comments (prevents loops)
if (event.actorType !== "user") return;
@@ -907,7 +973,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 הזה נועד לתת.
@@ -1025,9 +1091,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)}`,
@@ -1104,7 +1170,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) {