-
Notifications
You must be signed in to change notification settings - Fork 0
Transform Example
A minimal reference transform. Demonstrates the canonical shape of a transform hook that reshapes a tool result before it reaches the LLM. Reference only — normative shape and rules live in Hooks (contract).
A transform hook mutates payload in-flight between a turn stage's body and its consumers. This example truncates a Bash tool's stdout to a maximum length before the result lands in message history. Without it, a verbose command (e.g., ls -R /) can crowd the context window; with it, long outputs are trimmed with a clear marker.
This is a different kind of work than a Context Provider — a CP decides what to include at assembly time. A transform reshapes what already exists at a later stage. If you are contributing new content to the LLM request, write a CP, not a transform (per Hook Taxonomy § What hooks are not).
| Field | Value |
|---|---|
| Kind |
Hook. |
subKind |
transform. |
| Attachment |
TOOL_CALL/post. |
| Firing |
sync (transforms are always sync — see Firing mode). |
| Validation severity | Optional by default per Hooks § Validation severity. A load failure emits a warning; the session runs without the hook. |
| State slot | None needed. Transforms should be deterministic. |
flowchart LR
Body[TOOL_CALL body<br/>completed with stdout] --> Pre[read result.stdout]
Pre --> Check{length ><br/>maxBytes?}
Check -->|no| Pass[return result unchanged]
Check -->|yes| Trunc["truncate + append marker:<br/>... truncated N bytes ..."]
Trunc --> Out[return new result]
Pass --> Next[next transform / observer]
Out --> Next
Transform rules visible in the flow:
- The transform sees the tool result as payload.
- It returns a new payload. No side effects, no events — those belong to observers.
- The next transform in the slot's ordering manifest sees this transform's output.
- Transforms are deterministic. A transform that reads the wall clock or a random seed breaks replay determinism (see Hooks § Security notes — Transform hooks must be deterministic).
| Field | Meaning | Default |
|---|---|---|
enabled |
Whether the hook participates. |
true. |
maxBytes |
Maximum stdout length before truncation. |
8192. |
marker |
String appended to indicate truncation occurred. |
... truncated {n} bytes .... |
tools[] |
Tool names the transform applies to. |
["Bash"]. |
-
It does not read env. Transforms on
COMPOSE_REQUESTorTOOL_CALLthat splice env values into LLM-visible payload violate LLM Context Isolation. That constraint applies here: the transform reshapes what is already visible, it does not add new-visible content. - It does not vote. A transform cannot refuse to return a payload. A transform that wants to block the call is a guard instead.
- It does not call tools. Only the message loop calls tools.
- It does not drive interaction. No approval prompts, no auth dialogs. See Hook Taxonomy § Hook vs. SM, hook vs. command.
- You need to reshape a payload (normalize case, redact, truncate, wrap).
- The reshape is deterministic and depends only on its input.
- The reshape belongs between stages, not at context-assembly time.
Do not use a transform for:
- Adding new LLM-visible content — write a Context Provider with the appropriate capability declaration.
- Recording what was reshaped for analytics — attach a sibling
observeron the same slot. - Blocking the call — use a
guard.
- Execution Model
- Message Loop
- Concurrency and Cancellation
- Error Model
- Event and Command Ordering
- Event Bus
- Command Model
- Interaction Protocol
- Hook Taxonomy
- Host API
- Extension Lifecycle
- Env Provider
- Prompt Registry
- Resource Registry
- Session Lifecycle
- Session Manifest
- Persistence and Recovery
- Stage Executions
- Subagent Sessions
- Contract Pattern
- Versioning and Compatibility
- Deprecation Policy
- Capability Negotiation
- Dependency Resolution
- Validation Pipeline
- Cardinality and Activation
- Extension State
- Conformance and Testing
- Providers
- Provider Params
- Tools
- Hooks
- UI
- Loggers
- State Machines
- SM Stage Lifecycle
- Stage Definitions
- Commands
- Session Store
- Context Providers
- Settings Shape
- Trust Model
- Project Trust
- Extension Isolation
- Extension Integrity
- LLM Context Isolation
- Secrets Hygiene
- Security Modes
- Tool Approvals
- MCP Trust
- Sandboxing
- Configuration Scopes
- Project Root
- Extension Discovery
- Extension Installation
- Extension Reloading
- Headless and Interactor
- Determinism and Ordering
- Launch Arguments
- Network Policy
- Platform Integration
Tools
UI
Session Stores
Loggers
Providers
Hooks
Context Providers
Commands
- First Run
- Default Chat
- Tool Call Cycle
- Hook Interception
- Guard Deny Reproposal
- State Machine Workflow
- SM Stage Retry
- Hot Model Switch
- Capability Mismatch Switch
- Session Resume
- Session Resume Drift
- Approval and Auth
- Interaction Timeout
- Headless Run
- Parallel Tool Approvals
- Subagent Delegation
- Scope Layering
- Project First-Run Trust
- Reload Mid-Turn
- Compaction Warning
- MCP Remote Tool Call
- MCP Prompt Consume
- MCP Resource Bind
- MCP Reconnect