> ## Documentation Index
> Fetch the complete documentation index at: https://docs.astrakairo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Pulse.Console Runtime Service Reference

> Reference for the Pulse.Console runtime service: writing to stdout and stderr from Kairo applications using out and error streams.

`Pulse.Console` is the standard runtime service for writing text output from a Kairo application. It provides two named streams — `out` for standard output and `error` for standard error — each with `write` and `writeLine` methods. This page covers the import requirement, every method on both streams, accepted types, and a complete working example.

## Import Requirement

`Pulse.Console` is **not** a global or a keyword. You must explicitly import it before use.

```kairo theme={null}
import Pulse.Console
```

<Warning>
  Omitting the import and calling `Pulse.Console.out.writeLine(...)` is a compile error. There is no ambient access to `Pulse.Console`.
</Warning>

## `Pulse.Console.out` — Standard Output

The `out` stream writes to the process's standard output (`stdout`).

### `Pulse.Console.out.writeLine`

Writes a value to stdout followed by a newline character.

```kairo theme={null}
Pulse.Console.out.writeLine("Hello, world!")
Pulse.Console.out.writeLine(42)
```

<ParamField body="value" type="Text | Bool | Int32 | Int64 | Decimal | Float64 | enum | value | object" required>
  The value to write. See [Accepted Types](#accepted-types) for the full list of supported types.
</ParamField>

***

### `Pulse.Console.out.write`

Writes a value to stdout **without** a trailing newline. Use this when you need fine-grained control over line breaks.

```kairo theme={null}
Pulse.Console.out.write("Loading")
Pulse.Console.out.write("...")
Pulse.Console.out.writeLine(" done")
// stdout: Loading... done
```

<ParamField body="value" type="Text | Bool | Int32 | Int64 | Decimal | Float64 | enum | value | object" required>
  The value to write. See [Accepted Types](#accepted-types) for the full list of supported types.
</ParamField>

## `Pulse.Console.error` — Standard Error

The `error` stream writes to the process's standard error (`stderr`). It is structurally identical to `out` — the only difference is the destination stream.

### `Pulse.Console.error.writeLine`

Writes a value to stderr followed by a newline character.

```kairo theme={null}
Pulse.Console.error.writeLine("Something went wrong")
```

<ParamField body="value" type="Text | Bool | Int32 | Int64 | Decimal | Float64 | enum | value | object" required>
  The value to write. See [Accepted Types](#accepted-types) for the full list of supported types.
</ParamField>

***

### `Pulse.Console.error.write`

Writes a value to stderr **without** a trailing newline.

```kairo theme={null}
Pulse.Console.error.write("Error code: ")
Pulse.Console.error.writeLine(42)
```

<ParamField body="value" type="Text | Bool | Int32 | Int64 | Decimal | Float64 | enum | value | object" required>
  The value to write. See [Accepted Types](#accepted-types) for the full list of supported types.
</ParamField>

## Accepted Types

All four methods accept the same set of types:

| Type category | Types                            |
| ------------- | -------------------------------- |
| Text          | `Text`                           |
| Boolean       | `Bool`                           |
| Integers      | `Int32`, `Int64`                 |
| Numeric       | `Decimal`, `Float64`             |
| Enum          | Any `enum` value                 |
| Composite     | Any `value` or `object` instance |

<Note>
  When you pass a `value` or `object` instance, Pulse renders a default text representation. The exact format is runtime-defined and intended for diagnostics and development use, not for user-facing output.
</Note>

## Thread Safety

`Pulse.Console` is not thread-safe in Pulse MVP. Do not call console methods concurrently from multiple async branches without explicit synchronization.

## Quick Reference

| Method                                 | Stream | Newline |
| -------------------------------------- | ------ | ------- |
| `Pulse.Console.out.writeLine(value)`   | stdout | Yes     |
| `Pulse.Console.out.write(value)`       | stdout | No      |
| `Pulse.Console.error.writeLine(value)` | stderr | Yes     |
| `Pulse.Console.error.write(value)`     | stderr | No      |

## Complete Example

The following program imports `Pulse.Console` and demonstrates writing scalars, an enum value, and a `value` instance to both streams.

```kairo theme={null}
module My.App.Hello

import Pulse.Console

public enum Severity {
    info
    warning
    error
}

public value LogEntry {
    severity: Severity
    message: Text
}

func log(entry: LogEntry) {
    match entry.severity {
        Severity.error: {
            Pulse.Console.error.write("[ERROR] ")
            Pulse.Console.error.writeLine(entry.message)
        }
        Severity.warning: {
            Pulse.Console.out.write("[WARN]  ")
            Pulse.Console.out.writeLine(entry.message)
        }
        else: {
            Pulse.Console.out.write("[INFO]  ")
            Pulse.Console.out.writeLine(entry.message)
        }
    }
}

public func main() {
    let started: LogEntry = LogEntry { severity: Severity.info, message: "Application started" }
    let problem: LogEntry = LogEntry { severity: Severity.error, message: "Database unreachable" }

    log(started)
    log(problem)

    Pulse.Console.out.write("Active users: ")
    Pulse.Console.out.writeLine(0)

    Pulse.Console.out.writeLine(true)   // Bool
    Pulse.Console.out.writeLine(3.14)   // Decimal
}
```

**Expected stdout:**

```
[INFO]  Application started
Active users: 0
true
3.14
```

**Expected stderr:**

```
[ERROR] Database unreachable
```

<Tip>
  Always write error messages and diagnostic output to `Pulse.Console.error`, not `Pulse.Console.out`. This allows users and tooling to separate normal output from error output using standard stream redirection.
</Tip>

## Minimal Working Example

The following is the simplest valid Kairo program that uses `Pulse.Console`:

```kairo theme={null}
module Demo.ConsoleExample
import Pulse.Console

public func main(): Int32 {
    Pulse.Console.out.writeLine("Kairo speaks")
    return 0
}
```
