Harness

Custom guards

Write your own guard as a function of the call, or as a full guard with before and after hooks.

A guard is a name plus a before hook (looks at the call), an after hook (looks at the result), or both. define builds one from functions.

guards.define("no-weekend-refunds", (call) =>  call.tool === "refund_invoice" && [0, 6].includes(new Date().getUTCDay())    ? call.guide("Refunds wait until Monday; offer to schedule one.")    : call.proceed());
LanguageSignature
TypeScriptguards.define(name, before, { mode?, after? })
Pythonguards.define(name, before=None, *, after=None, mode=None)
RubyScute::Guards.define(name, mode: nil, after: nil) { |call| ... }

Returning nothing (undefined, None, nil) means proceed. Throwing counts as deny when the guard is enforced.

The call#

FieldMeaning
idThe tool call id (from the framework, or random)
toolThe tool name
argsThe arguments, after any earlier guard's transform. Ruby uses symbol keys.
permission, tier, resourceFrom the tool mapping
specThe full mapping: permission, action, resourceType (resource_type), tier
messagesThe conversation, when the integration passed it
approvedByUserThe person confirmed this exact call in the framework (Python approved_by_user, Ruby approved_by_user?)
modeThe mode of the guard looking at the call
clearNo enforced guard so far stops the call
runThe run, for state such as verifiedAt() or snapshot()

Answers#

HelperDecision
call.proceed()proceed
call.transform(args, message?)transform: run with these arguments (the full set)
call.approve(message?)approve by the person (approve.by is user)
call.verify(message?, options?)verify, options method, methods, permission (default: the call's permission)
call.guide(message, reason?)guide, default reason guided
call.redirect(to, message?)redirect to another tool or route
call.deny(message, reason?)deny, default reason denied

In Python, call.verify(message, methods=[...]) takes options as keywords; in Ruby, call.verify(message, methods: [...]).

After hooks#

An after hook gets the call and the result and can replace what the model reads. Return a decision with a result to replace it; a guide, redirect or deny without one replaces the result with { "error": "<message>" }.

guards.define("hide-internal-notes", () => undefined, {  after: (call, result) =>    call.tool === "read_ticket" && result && typeof result === "object"      ? { kind: "transform", reason: "redacted", result: { ...result, internal_notes: undefined } }      : undefined,});

A full guard#

For state, options or side effects, write the guard yourself.

import type { Guard } from "@scute/harness";const businessHours: Guard = {  name: "business-hours",  mode: "monitor",  before(call) {    const hour = new Date().getUTCHours();    if (call.tier === "high" && (hour < 8 || hour >= 18)) return call.deny("High-risk actions run in business hours only.", "after_hours");  },};
  • A guard with side effects (sending a push, filing a request) should act only when call.mode is enforce.
  • A guard that spends a single-use proof should act only when call.clear is true. TypeScript guards can set runsLast: true to run after the others; in Python set the class attribute runs_last = True; in Ruby define runs_last? to return true.