UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

48 lines • 2.35 kB
/** * The `trust` object a provider failure carries when the request failed TLS chain verification while * this engine runs on a fallback trust generation (omo#10762, design r13 6.6; senpi#5244). The code * comes only from the adapter's structured transport diagnostic, which reads the native error's * `code`, never message text. The object and its diagnostics record name no host, path or certificate. */ import { appendFile } from "node:fs/promises"; import { dirname, join } from "node:path"; import { isTlsChainVerificationCode } from "@earendil-works/pi-ai"; import { engineTrustAction } from "./actions.js"; import { adoptedEngineTrust } from "./adopted.js"; /** Reasons this process already wrote a record for: one record per process and reason. */ const recordedReasons = new Set(); export function transportTrustFailure(diagnostic) { if (diagnostic?.evidence !== "structured_transport" || diagnostic.code === undefined) return undefined; if (!isTlsChainVerificationCode(diagnostic.code)) return undefined; const trust = adoptedEngineTrust(); if (trust?.automatic !== "fallback" || trust.fallbackReason === null) return undefined; const reason = trust.fallbackReason; if (!recordedReasons.has(reason)) { recordedReasons.add(reason); appendDiagnosticsRecord(trust.file, { v: 1, at: new Date().toISOString(), pid: process.pid, generation: trust.sha256, codes: ["trust-tls-failed-under-fallback", reason], }); } return { code: "trust-tls-failed-under-fallback", reason, action: engineTrustAction(reason).id }; } /** * One line, in one append, to `diagnostics.jsonl` beside the generation file (design 5.3). The append * is asynchronous because this runs on the RPC session path, which takes no blocking filesystem call * (no-sync-in-session-path). A record that cannot be written costs only the record: the failure still * carries its `trust` object. */ function appendDiagnosticsRecord(generationFile, record) { appendFile(join(dirname(generationFile), "diagnostics.jsonl"), `${JSON.stringify(record)}\n`, { mode: 0o600, }).catch(() => { // The trust directory may be gone or read-only; the record is diagnostic only. }); } //# sourceMappingURL=transport-failure.js.map