{"version":3,"file":"action-validator.d.ts","sourceRoot":"","sources":["../../../src/core/reliability/action-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAmC,sBAAsB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE1G,MAAM,WAAW,mBAAmB;IACnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,YAAY,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACtF;AAED,MAAM,WAAW,mBAAmB;IACnC,2EAA2E;IAC3E,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;IAC5D,oFAAoF;IACpF,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;IACpE,yFAAyF;IACzF,yBAAyB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;CACtE;AAED,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC7B;AAiBD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,sBAAsB,GAAG,sBAAsB,CAsClH","sourcesContent":["/**\n * Action Validator — Jensen-owned execution authority boundary.\n *\n * No model-proposed executable action may reach a tool without passing this\n * validator. It checks, in order:\n *\n *   1. tool exists in the registry\n *   2. arguments parse and satisfy the tool schema\n *   3. required arguments are present and correctly typed (schema)\n *   4. the action is not a mission-forbidden action\n *   5. the action respects the workspace/path boundary\n *   6. the action respects permission/effect policy\n *\n * Any failure returns a structured ActionValidationFailure and the tool is NOT\n * executed. The validator is provider-independent: the live integration injects\n * the real tool registry, boundary, and policy adapters.\n */\n\nimport type { ActionValidationFailureCategory, ActionValidationResult, ToolCallAction } from \"./types.js\";\n\nexport interface ToolSchemaValidator {\n\texists(name: string): boolean;\n\tvalidateArgs(\n\t\tname: string,\n\t\targs: Record<string, unknown>,\n\t): { ok: true; normalized: Record<string, unknown> } | { ok: false; message: string };\n}\n\nexport interface ActionPolicyAdapter {\n\t/** Return a reason string when the action is forbidden, else undefined. */\n\tforbiddenReason(action: ToolCallAction): string | undefined;\n\t/** Return a reason string when the action violates the boundary, else undefined. */\n\tboundaryViolationReason(action: ToolCallAction): string | undefined;\n\t/** Return a reason string when the action violates permission policy, else undefined. */\n\tpermissionViolationReason(action: ToolCallAction): string | undefined;\n}\n\nexport interface ActionValidatorContext {\n\tschema: ToolSchemaValidator;\n\tpolicy?: ActionPolicyAdapter;\n}\n\nconst NOOP_POLICY: ActionPolicyAdapter = {\n\tforbiddenReason: () => undefined,\n\tboundaryViolationReason: () => undefined,\n\tpermissionViolationReason: () => undefined,\n};\n\nfunction failure(\n\tcategory: ActionValidationFailureCategory,\n\tmessage: string,\n\trecoverable: boolean,\n\tdetails?: unknown,\n): ActionValidationResult {\n\treturn { ok: false, failure: { category, message, recoverable, details } };\n}\n\n/**\n * Validate a model-proposed tool call. Returns a normalized/validated argument\n * object on success; a structured failure otherwise. Never throws and never\n * executes anything.\n */\nexport function validateToolCallAction(action: ToolCallAction, ctx: ActionValidatorContext): ActionValidationResult {\n\tconst policy = ctx.policy ?? NOOP_POLICY;\n\n\tif (!ctx.schema.exists(action.tool)) {\n\t\treturn failure(\"UNKNOWN_TOOL\", `Tool ${action.tool} not found`, false, { tool: action.tool });\n\t}\n\n\tconst argsResult = ctx.schema.validateArgs(action.tool, action.arguments);\n\tif (!argsResult.ok) {\n\t\treturn failure(\"INVALID_ARGUMENTS\", `Tool ${action.tool}: ${argsResult.message}`, true, {\n\t\t\ttool: action.tool,\n\t\t});\n\t}\n\n\tconst normalizedArgs = argsResult.normalized;\n\n\tconst forbidden = policy.forbiddenReason(action);\n\tif (forbidden) {\n\t\treturn failure(\"FORBIDDEN_ACTION\", `Tool ${action.tool} is forbidden: ${forbidden}`, false, {\n\t\t\ttool: action.tool,\n\t\t});\n\t}\n\n\tconst boundary = policy.boundaryViolationReason(action);\n\tif (boundary) {\n\t\treturn failure(\"BOUNDARY_VIOLATION\", `Tool ${action.tool} violates workspace boundary: ${boundary}`, false, {\n\t\t\ttool: action.tool,\n\t\t});\n\t}\n\n\tconst permission = policy.permissionViolationReason(action);\n\tif (permission) {\n\t\treturn failure(\"PERMISSION_VIOLATION\", `Tool ${action.tool} is not permitted: ${permission}`, false, {\n\t\t\ttool: action.tool,\n\t\t});\n\t}\n\n\treturn { ok: true, action, normalizedArgs };\n}\n"]}