Skip to content

Interface: PolicyBuilder<THandle> ​

Defined in: builders/policy-builder.ts:113

Fluent builder for capability and sandbox policies (P.policy(id)).

Aggregates ordered guard clauses (fs.protect, fs.readOnly, node.allowBinaries), quota tripwires (fs.quotaTripwire), quantitative turn/cost/duration limits, and .extend(newId).

Extends ​

Type Parameters ​

Type ParameterDefault typeDescription
THandleunknownRuntime handle type of the active isolation scope.

Methods ​

extend() ​

ts
extend(newId): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:211

Clones this policy under newId, inheriting all existing clauses, tripwires, limits, and hooks.

Re-keys inherited guard clause IDs deterministically as "${newId}:clause:${i}".

Parameters ​

ParameterTypeDescription
newIdstringUnique identifier for the derived policy.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder initialized with inherited state.


guard() ​

ts
guard(...guards): PolicyGuardClauseBuilder<THandle>;

Defined in: builders/policy-builder.ts:126

Starts a new guard clause inspecting pre-flight or post-flight ToolEffect lists.

Returns a PolicyGuardClauseBuilder requiring .onViolation(...) to complete the clause.

Parameters ​

ParameterTypeDescription
...guardsreadonly MaybeBuilder<PolicyGuardASTNode>[]Guard AST nodes or builders.

Returns ​

PolicyGuardClauseBuilder<THandle>

Pending clause builder requiring .onViolation(...).


maxCostUsd() ​

ts
maxCostUsd(costUsd): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:163

Sets the maximum cumulative USD cost allowed per actor execution under this policy.

Breaching costUsd triggers onLimitExceeded (if configured) or terminates the step.

Parameters ​

ParameterTypeDescription
costUsdnumberPositive USD cost ceiling.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.


maxDurationSeconds() ​

ts
maxDurationSeconds(seconds): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:174

Sets the maximum wall-clock duration in seconds allowed per actor execution under this policy.

Breaching seconds triggers onLimitExceeded (if configured) or terminates the step.

Parameters ​

ParameterTypeDescription
secondsnumberPositive duration ceiling in seconds.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.


maxTurns() ​

ts
maxTurns(turns): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:152

Sets the maximum number of model turns allowed per actor execution under this policy.

Breaching turns triggers onLimitExceeded (if configured) or terminates the step.

Parameters ​

ParameterTypeDescription
turnsnumberPositive integer turn ceiling.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.


onAbort() ​

ts
onAbort(abortHook): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:185

Binds a policy-level default abort hook (git.snapshotAndReset()) for unhooked .replaceWith() edges.

Satisfies Tier-1 'scope' replacement requirements when a step's .replaceWith() omits .onAbort().

Parameters ​

ParameterTypeDescription
abortHookMaybeBuilder<AbortHookASTNode<THandle, Record<string, unknown>>>Abort hook AST node or builder.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.


onLimitExceeded() ​

ts
onLimitExceeded(configure): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:198

Configures the limit-exceeded flush interrupt and optional abort hook when a quantitative limit is reached.

Invokes configure with a PolicyLimitExceededBuilder and stores the compiled config.

Parameters ​

ParameterTypeDescription
configure($limit) => PolicyLimitExceededBuilder<THandle>Limit-exceeded configurator callback.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.


toAST() ​

ts
toAST(): PolicyNode;

Defined in: ast/ast-builder.ts:20

Compiles the current builder configuration into a deeply frozen passive AST node.

Validates required builder invariants at compilation time and returns an immutable plain-object AST representation containing zero execution methods.

Returns ​

PolicyNode

Deeply frozen passive AST node.

Inherited from ​

AstBuilder.toAST


tripwire() ​

ts
tripwire(...tripwires): PolicyBuilder<THandle>;

Defined in: builders/policy-builder.ts:139

Appends stateful QuotaTripwireASTNode monitors (fs.quotaTripwire) evaluated across cumulative effects.

Tripwires raise their configured interrupt when cumulative workspace mutations exceed thresholds.

Parameters ​

ParameterTypeDescription
...tripwiresreadonly MaybeBuilder<FsQuotaTripwireNode>[]Quota tripwire AST nodes or builders.

Returns ​

PolicyBuilder<THandle>

New immutable policy builder.

Properties ​

PropertyModifierTypeDescriptionDefined in
idreadonlystringUnique identifier of the policy.builders/policy-builder.ts:115

Released under the MIT License.