UNPKG

@code-yeongyu/senpi

Version:

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

44 lines • 2.96 kB
/** * The trust annotation on agent-shell results (omo#10762, design r13 6.7). Under a fallback generation a * command that exits non-zero carries a trusted status taken from the adopted record and, only when its * output looks like a certificate verification error, an untrusted hint naming the matched catalog pattern. * The output never supplies a reason or an action: any command can print any text, including a forged * Bun footer or trust line (design M16). Like `adopted.ts`, this module does not load the marker parser. */ import { engineTrustAction } from "./actions.js"; import { adoptedEngineTrust } from "./adopted.js"; /** A verification code (design 6.6) as a whole token, whatever quotes surround it. */ const token = (code) => new RegExp(`(?<![A-Za-z0-9_])${code}(?![A-Za-z0-9_])`, "u"); /** Catalog order decides which entry a hint names when several match. */ const SHELL_TRUST_PATTERNS = [ ["UNABLE_TO_GET_ISSUER_CERT_LOCALLY", token("UNABLE_TO_GET_ISSUER_CERT_LOCALLY")], ["UNABLE_TO_GET_ISSUER_CERT", token("UNABLE_TO_GET_ISSUER_CERT")], ["UNABLE_TO_VERIFY_LEAF_SIGNATURE", token("UNABLE_TO_VERIFY_LEAF_SIGNATURE")], ["SELF_SIGNED_CERT_IN_CHAIN", token("SELF_SIGNED_CERT_IN_CHAIN")], ["DEPTH_ZERO_SELF_SIGNED_CERT", token("DEPTH_ZERO_SELF_SIGNED_CERT")], ["CERT_UNTRUSTED", token("CERT_UNTRUSTED")], ["unable-to-verify-the-first-certificate", /unable to verify the first certificate/iu], ["unable-to-get-local-issuer-certificate", /unable to get local issuer certificate/iu], ["unable-to-get-issuer-certificate", /unable to get issuer certificate/iu], ["self-signed-certificate-in-certificate-chain", /self[- ]signed certificate in certificate chain/iu], ["self-signed-certificate", /self[- ]signed certificate/iu], ["certificate-not-trusted", /certificate not trusted/iu], ]; /** Nothing without an adopted fallback generation, on exit 0, or for a command that has no exit code. */ export function annotateShellTrust({ exitCode, output, }) { const marker = adoptedEngineTrust(); if (marker?.automatic !== "fallback" || marker.fallbackReason === null || exitCode === null || exitCode === 0) { return undefined; } const reason = marker.fallbackReason; const action = engineTrustAction(reason); const status = { code: "trust-import-degraded", reason, action: action.id }; const pattern = SHELL_TRUST_PATTERNS.find(([, matcher]) => matcher.test(output))?.[0]; if (pattern === undefined) return { trust: { status }, text: undefined }; return { trust: { status, hint: { code: "tls-verify-text-in-output", heuristic: true, pattern } }, text: `omo: certificate import is degraded (${reason}), so some TLS connections may fail. This command's output contains text that looks like a certificate verification error; omo has not confirmed the cause. To diagnose: ${action.text}`, }; } //# sourceMappingURL=shell-trust.js.map