Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ The engine (`IdLE.Core`) must **not** depend on:

Use the single event contract:

- `Context.EventSink.WriteEvent(Type, Message, StepName, Data)`
- `Context.EventSink.WriteEvent(Type, Message, StepName, Data[, Level])`
- This is the runtime contract used by steps/providers through the execution context.
- `Type` follows the namespace scheme (`IdLE.<Area>.<Event>` first-party, `<Owner>.IdLE.<Area>.<Event>` extensions);
severity goes into `Level` (`Information` default, `Warning`, `Error`), never into `Type`.
- New or renamed first-party event types MUST be listed in `docs/extend/events.md` (type, level, data fields).
- External event sinks (host implementations) must follow the guidance in `docs/extend/events.md` (object-based event payload), but the engine-facing API remains `Context.EventSink.WriteEvent(...)`.

Do not introduce alternative eventing APIs unless explicitly planned and documented.
Expand Down
134 changes: 120 additions & 14 deletions docs/extend/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ This document covers:
- Why events exist in IdLE
- Where and when events are created
- How events are collected and exposed
- Event types, levels and data fields
- Responsibilities of engine, steps, and host environments
- Recommended usage patterns

Out of scope:

- Detailed API or property reference of event objects
- Logging frameworks or telemetry backends
- Implementation details of specific steps

Expand Down Expand Up @@ -61,24 +61,130 @@ Those decisions belong to the **host environment**.

Events are created at well-defined points during plan execution:

- **Run-level events**
- `RunStarted`
- `RunCompleted`

- **Step-level events**
- `StepStarted`
- `StepCompleted`
- `StepFailed`
- `StepSkipped`

- **Custom events**
- Explicitly emitted by steps (for example via an `EmitEvent` step)
- **Run-level events** (`IdLE.Run.*`) when a plan starts and finishes
- **Step-level events** (`IdLE.Step.*`, `IdLE.OnFailure.*`) when a step starts, completes, fails or is skipped
- **Domain events** emitted by steps and providers (for example `IdLE.Step.DirectorySync.Completed`)
- **Workflow-defined events** from `PreconditionEvent` and the `IdLE.Step.EmitEvent` step

All events share a common intent:
> describe *what happened*, not *how it should be presented*.

---

### Event object

Every event is an object with `PSTypeName = 'IdLE.Event'`:

| Property | Description |
| --- | --- |
| `TimestampUtc` | UTC timestamp. |
| `Type` | What happened (see [Event types](#event-types)). |
| `Level` | How severe it is: `Information`, `Warning` or `Error`. |
| `Message` | Human-readable message. Do not parse it; use `Type` and `Data`. |
| `CorrelationId` | Correlation ID of the request. |
| `Actor` | Actor of the request. |
| `StepName` | Name of the step (empty for run-level events). |
| `Data` | Optional hashtable with structured details (redacted at output boundaries). |

Steps and providers write events through the execution context:

```powershell
$Context.EventSink.WriteEvent(Type, Message, StepName, Data[, Level])
```

`Level` is optional and defaults to `Information`.

---

### Event types

`Type` names the event; `Level` carries the severity. Sinks filter on both (for example: alert on
`Level = 'Error'`, audit on `IdLE.Provider.AD.AttributeChanged`).

| Emitted by | Format | Example |
| --- | --- | --- |
| IdLE (engine, first-party steps and providers) | `IdLE.<Area>.<Event>` | `IdLE.Step.Failed`, `IdLE.Provider.AD.AttributeChanged` |
| Extensions (third-party steps and providers) | `<Owner>.IdLE.<Area>.<Event>` | `Contoso.IdLE.Hr.ManagerSynced` |
| Workflows (`PreconditionEvent.Type`, `EmitEvent` `With.Type`) | free, but not `IdLE.*` | `Contoso.ManualActionRequired` |

Rules:

- `IdLE.*` is reserved for events emitted by IdLE. Workflow-defined event types starting with `IdLE.`
are rejected (`ReservedNamespace`); see [Step type names](steps.md#step-type-names) for the namespace scheme.
- `Information`, `Warning`, `Error` and `Custom` are not valid event types (`InvalidEventType`).
Use a descriptive type and set the severity with `Level`.
- Event types and their `Data` fields listed below are a contract. `Message` texts are not.

#### Engine events

| Type | Level | Data |
| --- | --- | --- |
| `IdLE.Run.Started` | Information | `CorrelationId`, `Actor`, `StepCount` |
| `IdLE.Run.Completed` | Information; `Warning` if `Blocked`; `Error` if `Failed` | `Status`, `StepCount` |
| `IdLE.Step.Started` | Information | `StepType`, `Index` |
| `IdLE.Step.Completed` | Information | `StepType`, `Index` |
| `IdLE.Step.Failed` | Error | `StepType`, `Index`, `Error` |
| `IdLE.Step.Blocked` | Warning | `StepType`, `Index` |
| `IdLE.Step.NotApplicable` | Information | `StepType`, `Index` |
| `IdLE.Step.PreconditionFailed` | Warning | `StepType`, `Index`, `OnPreconditionFalse` |
| `IdLE.Step.Retrying` | Warning | `attempt`, `maxAttempts`, `delayMs`, `errorType`, `message` |
| `IdLE.OnFailure.Started` | Information | `OnFailureStepCount` |
| `IdLE.OnFailure.Completed` | Information; `Warning` if `PartiallyFailed` | `Status`, `StepCount` |
| `IdLE.OnFailure.StepStarted` | Information | `StepType`, `Index` |
| `IdLE.OnFailure.StepCompleted` | Information | `StepType`, `Index` |
| `IdLE.OnFailure.StepFailed` | Error | `StepType`, `Index`, `Error` |
| `IdLE.OnFailure.StepNotApplicable` | Information | `StepType`, `Index` |

`IdLE.Run.Completed` is always the last event of a run.

#### Step events

| Type | Level | Data |
| --- | --- | --- |
| `IdLE.Step.EmitEvent.Emitted` | `With.Level` (default Information) | `StepType` |
| `IdLE.Step.DirectorySync.Triggered` | Information | `PolicyType`, `ComputerName` |
| `IdLE.Step.DirectorySync.Waiting` | Information | `TimeoutSeconds`, `PollIntervalSeconds` |
| `IdLE.Step.DirectorySync.Polled` | Information | `Attempt`, `State`, `InProgress`, `ElapsedSeconds` |
| `IdLE.Step.DirectorySync.Completed` | Information | `Attempts`, `ElapsedSeconds` (waited) or `PolicyType` (not waited) |
| `IdLE.Step.DirectorySync.Failed` | Error | `TimeoutSeconds`, `ElapsedSeconds`, `LastKnownState` (timeout) or `Error` |
| `IdLE.Step.PruneEntitlements.Planned` | Information | `Kind`, `KeepCount`, `PruneCount` |
| `IdLE.Step.PruneEntitlements.EntitlementRevoked` | Information | `Kind`, `EntitlementId` |
| `IdLE.Step.PruneEntitlements.EntitlementSkipped` | Warning | `Kind`, `EntitlementId`, `Reason` |
| `IdLE.Step.PruneEntitlements.KeepGranted` | Information | `Kind`, `EntitlementId` |
| `IdLE.Step.PruneEntitlements.KeepGrantFailed` | Warning | `Kind`, `EntitlementId`, `Reason` |

`IdLE.Step.EmitEvent` emits `IdLE.Step.EmitEvent.Emitted` unless the workflow sets `With.Type`.

#### Provider events

Providers emit events only when the host passes an event sink to the provider.

| Type | Level | Data |
| --- | --- | --- |
| `IdLE.Provider.AD.AttributesRequested` | Information | `IdentityKey`, `Requested` |
| `IdLE.Provider.AD.AttributeChanged` | Information | `IdentityKey`, `AttributeName`, `OldValue`, `NewValue` |
| `IdLE.Provider.ExchangeOnline.PermissionsEvaluated` | Information | `MailboxSmtp`, `Right`, `CurrentUsers` |
| `IdLE.Provider.ExchangeOnline.PermissionChanging` | Information | `MailboxSmtp`, `Right`, `User`, `Action` |
| `IdLE.Provider.ExchangeOnline.PermissionsEnsured` | Information | `MailboxSmtp`, `Changed` |

#### Migration from earlier versions

Event types were renamed in one step without aliases:

| Old type | New type |
| --- | --- |
| `RunStarted`, `RunCompleted` | `IdLE.Run.Started`, `IdLE.Run.Completed` |
| `StepStarted`, `StepCompleted`, `StepFailed`, `StepBlocked`, `StepNotApplicable`, `StepPreconditionFailed`, `StepRetrying` | `IdLE.Step.Started`, `.Completed`, `.Failed`, `.Blocked`, `.NotApplicable`, `.PreconditionFailed`, `.Retrying` |
| `OnFailureStarted`, `OnFailureCompleted` | `IdLE.OnFailure.Started`, `IdLE.OnFailure.Completed` |
| `OnFailureStepStarted`, `OnFailureStepCompleted`, `OnFailureStepFailed`, `OnFailureStepNotApplicable` | `IdLE.OnFailure.StepStarted`, `.StepCompleted`, `.StepFailed`, `.StepNotApplicable` |
| `DirectorySyncTriggered`, `DirectorySyncWaiting`, `DirectorySyncPoll`, `DirectorySyncCompleted`, `DirectorySyncFailed` | `IdLE.Step.DirectorySync.Triggered`, `.Waiting`, `.Polled`, `.Completed`, `.Failed` |
| `Information` / `Warning` (PruneEntitlements) | `IdLE.Step.PruneEntitlements.Planned`, `.EntitlementRevoked`, `.EntitlementSkipped`, `.KeepGranted`, `.KeepGrantFailed` |
| `Custom` (EmitEvent) | `IdLE.Step.EmitEvent.Emitted` or the workflow's `With.Type` |
| `Provider.AD.CreateIdentity.AttributesRequested`, `Provider.AD.EnsureAttribute.AttributeChanged` | `IdLE.Provider.AD.AttributesRequested`, `IdLE.Provider.AD.AttributeChanged` |
| `Provider.ExchangeOnline.Permissions.Evaluated`, `.Applying`, `.Result` | `IdLE.Provider.ExchangeOnline.PermissionsEvaluated`, `.PermissionChanging`, `.PermissionsEnsured` |

---

### Buffered by default

During execution, events are **buffered inside the execution result**.
Expand Down Expand Up @@ -132,7 +238,7 @@ The repository demo runner is an example of this pattern.
#### CI pipelines

- Inspect execution status
- Fail the pipeline if a `RunFailed` or `StepFailed` event exists
- Fail the pipeline if an event with `Level = 'Error'` exists (for example `IdLE.Step.Failed`)
- Optionally archive event output as build artifacts

#### Services and long-running hosts
Expand Down
4 changes: 2 additions & 2 deletions docs/extend/extensibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Extension step types and capabilities use your own owner prefix: `<Owner>.IdLE.S

Steps can emit structured events using the execution context contract:

- `Context.EventSink.WriteEvent(Type, Message, StepName, Data)`
- `Context.EventSink.WriteEvent(Type, Message, StepName, Data[, Level])` (see [Event types](events.md#event-types))

Keep steps host-agnostic: do not call UI APIs directly.

- Use providers for system operations; do not embed authentication logic inside steps.
- Emit events using `Context.EventSink.WriteEvent(Type, Message, StepName, Data)`.
- Emit events using `Context.EventSink.WriteEvent(Type, Message, StepName, Data[, Level])`.
- Avoid global state. Steps should be idempotent whenever possible.

---
Expand Down
13 changes: 8 additions & 5 deletions docs/extend/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,26 @@ Steps may emit **structured events** for progress and audit.

The engine provides a stable, object-based contract on the execution context:

- `Context.EventSink.WriteEvent(Type, Message, StepName, Data)`
- `Context.EventSink.WriteEvent(Type, Message, StepName, Data[, Level])`

Notes:

- `Type` is a short string (for example: `Custom`, `Debug`).
- `Type` says *what happened*: `IdLE.<Area>.<Event>` for first-party steps (e.g. `IdLE.Step.DirectorySync.Completed`),
`<Owner>.IdLE.<Area>.<Event>` for extensions (e.g. `Contoso.IdLE.Hr.ManagerSynced`).
See [Event types](events.md#event-types).
- `Message` is a human-readable message.
- `StepName` should be the current step name (if available).
- `Data` is an optional hashtable for structured details.
- `Level` says *how severe* it is: `Information` (default), `Warning` or `Error`.

Example:

```powershell
$Context.EventSink.WriteEvent(
'Custom',
'Ensured Department attribute.',
'Contoso.IdLE.Hr.ManagerSynced',
'Synced manager from HR.',
$Step.Name,
@{ Provider = 'Identity'; Attribute = 'Department' }
@{ Provider = 'Identity'; Attribute = 'Manager' }
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ and execution, as noted below.
| `With.PolicyType` | `string` | Required by provider | `Delta` or `Initial` sync policy |
| `With.Wait` | `bool` | `false` | Poll sync status and wait for result (or timeout) |
| `With.PollIntervalSeconds` | `int` | `10` | Interval in seconds to poll for sync status |
| `With.TimeoutSeconds` | `int` | `600` | Timeout for poll wait in seconds. Will result in `StepFailed` |
| `With.TimeoutSeconds` | `int` | `600` | Timeout for poll wait in seconds. Will result in `IdLE.Step.Failed` |

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| [IdLE.Step.CreateIdentity](steps/step-create-identity.md) | ``IdLE.Steps.Common`` | Creates a new identity in the target system. |
| [IdLE.Step.DeleteIdentity](steps/step-delete-identity.md) | ``IdLE.Steps.Common`` | Deletes an identity from the target system. |
| [IdLE.Step.DisableIdentity](steps/step-disable-identity.md) | ``IdLE.Steps.Common`` | Disables an identity in the target system. |
| [IdLE.Step.EmitEvent](steps/step-emit-event.md) | ``IdLE.Steps.Common`` | Emits a custom event (demo step). |
| [IdLE.Step.EmitEvent](steps/step-emit-event.md) | ``IdLE.Steps.Common`` | Emits a workflow-defined event. |
| [IdLE.Step.EnableIdentity](steps/step-enable-identity.md) | ``IdLE.Steps.Common`` | Enables an identity in the target system. |
| [IdLE.Step.EnsureAttributes](steps/step-ensure-attributes.md) | ``IdLE.Steps.Common`` | Ensures that multiple identity attributes match their desired values. |
| [IdLE.Step.EnsureEntitlement](steps/step-ensure-entitlement.md) | ``IdLE.Steps.Common`` | Ensures that an entitlement assignment is present or absent for an identity. |
Expand Down
18 changes: 14 additions & 4 deletions docs/reference/steps/step-emit-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@

## Synopsis

Emits a custom event (demo step).
Emits a workflow-defined event.

## Description

This step does not change external state. It emits a custom event message.
The engine provides an EventSink on the execution context that the step can use
to write structured events.
This step does not change external state. It writes one structured event to the
EventSink on the execution context (buffered in the execution result and forwarded
to the host event sink, if any).

Inputs (all optional):

- With.Message: event message. Defaults to "Event emitted by step '&lt;Name&gt;'.".

- With.Type: event type, e.g. 'Contoso.Joiner.Notified'. Must not start with 'IdLE.'
(reserved) and must not be 'Information', 'Warning', 'Error' or 'Custom'.
Defaults to 'IdLE.Step.EmitEvent.Emitted'.

- With.Level: 'Information' (default), 'Warning' or 'Error'.

## Inputs (With.*)

Expand Down
27 changes: 15 additions & 12 deletions docs/use/workflows/preconditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ Add these optional properties to a workflow step definition:

| Key | Type | Required | Description |
|---|---|---|---|
| `Type` | `String` | **Yes** | Event type string (for example: `ManualActionRequired`). |
| `Type` | `String` | **Yes** | Event type string (for example: `Contoso.ManualActionRequired`). Must not start with `IdLE.` (reserved) and must not be `Information`, `Warning`, `Error` or `Custom`. |
| `Message` | `String` | **Yes** | Human-readable description of the required action. |
| `Level` | `String` | No | `Information` (default), `Warning` or `Error`. |
| `Data` | `Hashtable` | No | Optional key-value payload. Must not contain secrets. |

---
Expand All @@ -107,8 +108,8 @@ When a step is `Blocked`:
- `result.Status` is `'Blocked'`.
- `result.Steps[n].Status` is `'Blocked'` for the blocking step.
- `result.OnFailure.Status` is `'NotRun'` (OnFailureSteps do not execute).
- A `StepPreconditionFailed` engine event is always emitted.
- A `StepBlocked` engine event is emitted for the blocked step.
- An `IdLE.Step.PreconditionFailed` engine event is always emitted.
- An `IdLE.Step.Blocked` engine event is emitted for the blocked step.
- If `PreconditionEvent` is configured, an additional event of the declared `Type` is also emitted.

### Execution result — Fail
Expand All @@ -118,8 +119,8 @@ When `OnPreconditionFalse = 'Fail'`:
- `result.Status` is `'Failed'`.
- `result.Steps[n].Status` is `'Failed'` with `Error = 'Precondition check failed.'`.
- `OnFailureSteps` run (same behavior as any other step failure).
- A `StepPreconditionFailed` engine event is always emitted.
- A `StepFailed` engine event is emitted (matching the format of regular step failure events).
- An `IdLE.Step.PreconditionFailed` engine event is always emitted.
- An `IdLE.Step.Failed` engine event is emitted (matching the format of regular step failure events).
- If `PreconditionEvent` is configured, an additional event of the declared `Type` is also emitted.

### Execution result — Continue
Expand All @@ -129,7 +130,7 @@ When `OnPreconditionFalse = 'Continue'`:
- `result.Status` is `'Completed'` (unless a subsequent step fails for another reason).
- `result.Steps[n].Status` is `'PreconditionSkipped'` for the skipped step.
- Subsequent steps execute as normal.
- A `StepPreconditionFailed` engine event is always emitted for observability.
- An `IdLE.Step.PreconditionFailed` engine event is always emitted for observability.
- If `PreconditionEvent` is configured, an additional event of the declared `Type` is also emitted.

Use `Continue` when a precondition failure is advisory rather than blocking — for example, to emit
Expand All @@ -142,16 +143,17 @@ the rest of the workflow to complete.

| Event type | `OnPreconditionFalse` modes | Description |
|---|---|---|
| `StepPreconditionFailed` | All (`Blocked`, `Fail`, `Continue`) | Always emitted. Contains `StepType`, `Index`, `OnPreconditionFalse`. |
| `StepBlocked` | `Blocked` | Emitted when the step outcome is `Blocked`. Contains `StepType`, `Index`. |
| `StepFailed` | `Fail` | Emitted when the step outcome is `Failed`. Contains `StepType`, `Index`, `Error`. |
| `IdLE.Step.PreconditionFailed` | All (`Blocked`, `Fail`, `Continue`) | Always emitted. Contains `StepType`, `Index`, `OnPreconditionFalse`. |
| `IdLE.Step.Blocked` | `Blocked` | Emitted when the step outcome is `Blocked`. Contains `StepType`, `Index`. |
| `IdLE.Step.Failed` | `Fail` | Emitted when the step outcome is `Failed`. Contains `StepType`, `Index`, `Error`. |
| Configured `PreconditionEvent.Type` | All (if `PreconditionEvent` configured) | Caller-defined event. |

### StepPreconditionFailed event
### IdLE.Step.PreconditionFailed event

| Field | Value |
|---|---|
| `Type` | `StepPreconditionFailed` |
| `Type` | `IdLE.Step.PreconditionFailed` |
| `Level` | `Warning` |
| `StepName` | The name of the affected step. |
| `Data.StepType` | The step type identifier. |
| `Data.Index` | The step index in the plan. |
Expand All @@ -164,6 +166,7 @@ If `PreconditionEvent` is configured, an additional event is emitted with:
| Field | Value |
|---|---|
| `Type` | The configured `PreconditionEvent.Type`. |
| `Level` | The configured `PreconditionEvent.Level` (default `Information`). |
| `Message` | The configured `PreconditionEvent.Message`. |
| `StepName` | The name of the affected step. |
| `Data` | The configured `PreconditionEvent.Data` (if provided). |
Expand Down Expand Up @@ -212,7 +215,7 @@ a `Blocked` outcome and a message instructing the operator to perform the wipe m
}
OnPreconditionFalse = 'Blocked'
PreconditionEvent = @{
Type = 'ManualActionRequired'
Type = 'Contoso.ManualActionRequired'
Message = 'Perform Intune retire / wipe company data for BYOD device before disabling the identity.'
Data = @{
Reason = 'BYOD wipe not confirmed'
Expand Down
27 changes: 18 additions & 9 deletions examples/Invoke-IdleDemo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ function Format-EventRow {
param([Parameter(Mandatory)][object]$EventRecord)

$icons = @{
RunStarted = '🚀'
RunCompleted = '🏁'
StepStarted = '▶️'
StepCompleted = '✅'
StepSkipped = '⏭️'
StepFailed = '❌'
Custom = '📝'
Debug = '🔎'
'IdLE.Run.Started' = '🚀'
'IdLE.Run.Completed' = '🏁'
'IdLE.Step.Started' = '▶️'
'IdLE.Step.Completed' = '✅'
'IdLE.Step.NotApplicable' = '⏭️'
'IdLE.Step.EmitEvent.Emitted' = '📝'
}

$icon = if ($icons.ContainsKey($EventRecord.Type)) { $icons[$EventRecord.Type] } else { '•' }
$icon = if ($icons.ContainsKey($EventRecord.Type)) {
$icons[$EventRecord.Type]
}
elseif ($EventRecord.Level -eq 'Error') {
'❌'
}
elseif ($EventRecord.Level -eq 'Warning') {
'⚠️'
}
else {
'•'
}

$time = ([DateTime]$EventRecord.TimestampUtc).ToLocalTime().ToString('HH:mm:ss.fff')
$step = if ([string]::IsNullOrWhiteSpace($EventRecord.StepName)) { '-' } else { [string]$EventRecord.StepName }
Expand Down
Loading
Loading