From 48c8b372bd36b08d305b6518a8ccf6c61bda8bf4 Mon Sep 17 00:00:00 2001 From: Yuri Yaryshev Date: Mon, 23 Nov 2026 19:27:12 +0300 Subject: [PATCH] =?UTF-8?q?Claude=20=D0=BF=D1=80=D0=B8=20=D1=87=D1=82?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B5=D0=B4=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B1=D0=B5=D0=B7?= =?UTF-8?q?=20MCP-=D0=BA=D0=BE=D0=BD=D0=BD=D0=B5=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B8=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D1=81=20Read=20=D0=B8=20Bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- packages/accounting_automation/src/claude-runner.ts | 6 ++++++ packages/accounting_automation/src/invoices-mail.ts | 3 ++- packages/accounting_automation/src/receipts.ts | 3 ++- packages/accounting_automation/src/reconcile.ts | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/accounting_automation/src/claude-runner.ts b/packages/accounting_automation/src/claude-runner.ts index 7ff17c1..7335827 100644 --- a/packages/accounting_automation/src/claude-runner.ts +++ b/packages/accounting_automation/src/claude-runner.ts @@ -15,6 +15,12 @@ export interface ClaudeRunResult { exitCode: number | null; timedOut: boolean; } +/** + * Аргументы для запусков, где Claude читает НЕДОВЕРЕННЫЕ документы (письма, вложения, чеки, выписки): без MCP-коннекторов + * (в письме не должно быть возможности заставить агента писать в QuickBooks) и только с инструментами чтения и shell. + */ +export const UNTRUSTED_DOC_ARGS = ["--strict-mcp-config", "--tools", "Read,Bash"]; + /** Запуск Claude-агента; в тестах подменяется. */ export type ClaudeRunner = (o: ClaudeRunOptions) => Promise; diff --git a/packages/accounting_automation/src/invoices-mail.ts b/packages/accounting_automation/src/invoices-mail.ts index 082477d..2bf7a0d 100644 --- a/packages/accounting_automation/src/invoices-mail.ts +++ b/packages/accounting_automation/src/invoices-mail.ts @@ -6,6 +6,7 @@ import { extname, join } from "node:path"; import { promisify } from "node:util"; import type { Logger, Pool } from "khb_common"; import type { ClaudeRunner } from "./claude-runner.js"; +import { UNTRUSTED_DOC_ARGS } from "./claude-runner.js"; import type { DriveStore } from "./drive.js"; import { ingestCertificate } from "./certificates-ingest.js"; import { normalizeVendorName } from "./vendor-name.js"; @@ -274,7 +275,7 @@ async function recognize(deps: InvoiceIngestDeps, msg: MailMessage, att: MailAtt const ext = extOf(att.filename); const path = join(dir, `invoice${DOC_EXT.has(ext) ? ext : ".bin"}`); await writeFile(path, bytes); - const res = await deps.claude({ prompt: buildRecognitionPrompt(path, msg), cwd: dir }); + const res = await deps.claude({ prompt: buildRecognitionPrompt(path, msg), cwd: dir, extraArgs: UNTRUSTED_DOC_ARGS }); if (!res.ok) throw new Error(`Claude не отработал (код ${res.exitCode}${res.timedOut ? ", таймаут" : ""}): ${res.stderr.slice(0, 200)}`); return parseRecognition(res.stdout); } finally { diff --git a/packages/accounting_automation/src/receipts.ts b/packages/accounting_automation/src/receipts.ts index e06ba53..2efb316 100644 --- a/packages/accounting_automation/src/receipts.ts +++ b/packages/accounting_automation/src/receipts.ts @@ -4,6 +4,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import type { Logger, Pool } from "khb_common"; import type { ClaudeRunner } from "./claude-runner.js"; +import { UNTRUSTED_DOC_ARGS } from "./claude-runner.js"; import type { DriveStore } from "./drive.js"; import { normalizeVendorName, parseAmount, resolveProject } from "./invoices-mail.js"; import type { SlackApi, SlackFile, SlackMessage } from "./slack.js"; @@ -215,7 +216,7 @@ async function recognize(deps: ReceiptsDeps, file: SlackFile, bytes: Buffer): Pr try { const path = join(dir, `receipt.${extOf(file)}`); await writeFile(path, bytes); - const res = await deps.claude({ prompt: buildReceiptPrompt(path), cwd: dir }); + const res = await deps.claude({ prompt: buildReceiptPrompt(path), cwd: dir, extraArgs: UNTRUSTED_DOC_ARGS }); if (!res.ok) throw new Error(`Claude не отработал (код ${res.exitCode}${res.timedOut ? ", таймаут" : ""}): ${res.stderr.slice(0, 200)}`); return parseReceiptRecognition(res.stdout); } finally { diff --git a/packages/accounting_automation/src/reconcile.ts b/packages/accounting_automation/src/reconcile.ts index cd51913..380ab3b 100644 --- a/packages/accounting_automation/src/reconcile.ts +++ b/packages/accounting_automation/src/reconcile.ts @@ -4,6 +4,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { withTx, type Logger, type Pool } from "khb_common"; import type { ClaudeRunner } from "./claude-runner.js"; +import { UNTRUSTED_DOC_ARGS } from "./claude-runner.js"; import { parseAmount } from "./invoices-mail.js"; import type { SlackPoster } from "./slack.js"; @@ -106,7 +107,7 @@ export function makeClaudeStatementReader(o: { claude: ClaudeRunner; tmpDir?: st try { const path = join(dir, "statement.pdf"); await writeFile(path, bytes); - const res = await o.claude({ prompt: buildStatementPrompt(path), cwd: dir }); + const res = await o.claude({ prompt: buildStatementPrompt(path), cwd: dir, extraArgs: UNTRUSTED_DOC_ARGS }); if (!res.ok) throw new Error(`Claude не отработал (код ${res.exitCode}${res.timedOut ? ", таймаут" : ""}): ${res.stderr.slice(0, 200)}`); return parseStatement(res.stdout); } finally {