Validate trust verbs before executing wrapped functions#38
Merged
Conversation
…d wrap→verify round-trip test Issues fixed: - examples/langchain-agent.ts: replace console.log with process.stdout.write - src/index.ts: wrap() passes non-schema verbs to receipt (e.g. "summarize", "agent.execute", "tool.get_weather") — normalizeTrustVerb() only strips the clas.trust-verification. prefix, so verbs not in the schema enum are written into the receipt unchecked; add schema guard so wrap() throws on an unrecognized verb instead of producing a non-schema-valid receipt - test/receipt.test.ts: add explicit wrap→verify round-trip assertion on schema validity; existing "summarize" verb in tests now uses a valid enum verb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds validation of trust verbs to the CommandLayer, ensuring that only recognized verbs from the schema-defined TRUST_VERBS enum are accepted. Invalid verbs now throw a synchronous error before the wrapped function executes, rather than producing an invalid receipt.
Key Changes
resolveAndValidateTrustVerb()function insrc/index.tsthat normalizes and validates trust verbs against the TRUST_VERBS enum, throwing a descriptive error if the verb is unrecognizedCommandLayer.wrap()method to callresolveAndValidateTrustVerb()before executing the wrapped function, ensuring callers get immediate, synchronous feedback for invalid verbsvalidateTrustReceipt()function from the main index for use in tests and external validationlangchain-agent.tsto use valid verb ("attest") and improved output formattingImplementation Details
TRUST_VERB_SETas a ReadonlySet for efficient O(1) verb validation lookupshttps://claude.ai/code/session_016igMwkFir2FkLQCHL6a34z