Context-Aware Response Formatting
ARO automatically formats responses and log output based on the execution context. The same code produces different output formats depending on how it's invoked.
Execution Contexts
ARO recognizes three execution contexts:
| Context | Trigger | Output Format |
|---|---|---|
| Human | aro run, CLI execution |
Readable text |
| Machine | HTTP API, events | JSON/structured data |
| Developer | aro test, debug mode |
Detailed diagnostics |
How It Works
Human Context (Default)
When you run ARO from the command line, output is formatted for readability:
(Application-Start: Example) {
<Log> the <message> for the <console> with "Hello, World!".
<Return> an <OK: status> for the <startup>.
}
Running with aro run:
[Application-Start] Hello, World!
Machine Context
When code runs via HTTP request or event handler, output is structured data:
{"level":"info","source":"Application-Start","message":"Hello, World!"}
Developer Context
During test execution, output is displayed as a formatted table with type annotations:
┌──────────────────────────────────────────┐
│ LOG [console] Application-Start │
├──────────────────────────────────────────┤
│ message: String("Hello, World!") │
└──────────────────────────────────────────┘
Automatic Detection
The runtime automatically detects context:
| Entry Point | Context |
|---|---|
aro run command |
Human |
aro test command |
Developer |
| HTTP route handler | Machine |
| Event dispatch | Machine |
--debug flag |
Developer |
Example: Same Code, Different Contexts
(getUser: User API) {
<Retrieve> the <user> from the <user-repository> where id = <id>.
<Log> the <status> for the <console> with "User retrieved".
<Return> an <OK: status> with <user>.
}
CLI Output (Human)
[getUser] User retrieved
[OK] success
user.id: 123
user.name: Alice
HTTP Response (Machine)
{
"status": "OK",
"reason": "success",
"data": {
"user": {"id": 123, "name": "Alice"}
}
}
Test Output (Developer)
┌──────────────────────────────────────────┐
│ LOG [console] getUser │
├──────────────────────────────────────────┤
│ message: String("User retrieved") │
└──────────────────────────────────────────┘
┌──────────────────────────────────────────┐
│ Response<OK> │
├────────────────┬─────────────────────────┤
│ reason │ String("success") │
│ user.id │ Int(123) │
│ user.name │ String("Alice") │
└────────────────┴─────────────────────────┘
Benefits
- Write Once: No need for separate formatting code
- Automatic Adaptation: Output suits the consumer automatically
- Consistent Behavior: Same logic, appropriate presentation
- Debug Friendly: Rich diagnostics during development
Integration with Actions
Log Action
The <Log> action respects output context:
<Log> the <message> for the <console> with <value>.
- Human:
[FeatureSetName] value - Machine:
{"level":"info","source":"FeatureSetName","message":"value"} - Developer: Formatted table with type annotations
Return Action
The <Return> action sets the response, which is formatted based on context:
<Return> an <OK: status> with <result>.
See Also
- Actions - Built-in action reference
- HTTP Services - API development