Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
feat(mcp): export deliveryRefusal and ContractErrorException from pane/
Jack Rudenko3833e618f095
diff --git a/packages/cli/src/pane/contract.ts b/packages/cli/src/pane/contract.tsindex 91f72664..350c7535 100644--- a/packages/cli/src/pane/contract.ts+++ b/packages/cli/src/pane/contract.ts@@ -247,3 +247,20 @@ export interface ContractError {export function contractMeta(): ContractMeta {return { contract_version: CONTRACT_VERSION, capabilities: [...CAPABILITIES] };}++/**+ * A §8 verb's error, thrown by the owners and serialised by the MCP handler as the+ * `ContractError` JSON with `isError: true` (§8 E).+ */+export class ContractErrorException extends Error {+ constructor(+ readonly code: ContractError["error"]["code"],+ message: string+ ) {+ super(message);+ }++ toContractError(): ContractError {+ return { error: { code: this.code, message: this.message } };+ }+}diff --git a/packages/cli/src/pane/index.ts b/packages/cli/src/pane/index.tsindex 3dda4c30..715b9742 100644--- a/packages/cli/src/pane/index.ts+++ b/packages/cli/src/pane/index.ts@@ -6,6 +6,7 @@export * from "./contract.js";export { toSlotRow } from "./slot-row.js";+export { deliveryRefusal } from "./prompt-delivery.js";export {type Accounting,mergeAccounting,diff --git a/packages/cli/src/pane/prompt-delivery.ts b/packages/cli/src/pane/prompt-delivery.tsindex 42fc7680..04acb6e2 100644--- a/packages/cli/src/pane/prompt-delivery.ts+++ b/packages/cli/src/pane/prompt-delivery.ts@@ -213,6 +213,16 @@ export function planDelivery(};}+/**+ * Why `text` cannot be delivered at all (§2.3 rule 4: the flags remove Read and the text+ * is neither a plain line nor a one-line command), or null when it can. Pure; owners call+ * it before anything is spawned, so the refusal is `invalid_args`, not a failed slot.+ */+export function deliveryRefusal(text: string, readAvailable: boolean): string | null {+ const plan = planDelivery(text, "/nonexistent", 1, readAvailable);+ return plan.mode === "refused" ? plan.reason : null;+}+/** Write a delivery's turn file: exclusive create, mode 0600. No-op for typed/control deliveries. */export function writeTurnFile(d: Delivery): void {if ((d.mode === "file" || d.mode === "command") && d.file && d.fileContent !== undefined) {